DEV Community

Takuya Matsuyama
Takuya Matsuyama

Posted on

Fixing gradle errors of C++ JSI native modules

I have a React Native project with some JSI native modules implemented in C++ like react-native-quick-base64.
Today I upgraded Android Studio to 4.2.1, and it failed to build my project with the following CMake error:

/Users/***/Library/Android/sdk/cmake/3.6.4111459/bin/cmake -H/Users/***/Developments/inkdrop/inkdrop-mobile/node_modules/react-native-quick-base64/android -B/Users/***/Developments/inkdrop/inkdrop-mobile/node_modules/react-native-quick-base64/android/.cxx/cmake/release/armeabi-v7a
CMake Error at .cxx/cmake/release/armeabi-v7a/CMakeFiles/3.6.0-rc2/CMakeSystem.cmake:6 (include):
  include could not find load file:

    /Users/***/Library/Android/sdk/ndk/23.0.7123448/build/cmake/android.toolchain.cmake
Call Stack (most recent call first):
  CMakeLists.txt


-- The C compiler identification is AppleClang 12.0.5.12050022
-- The CXX compiler identification is AppleClang 12.0.5.12050022
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
CMake Error at /Users/***/Developments/inkdrop/inkdrop-mobile/node_modules/react-native-quick-base64/android/.cxx/cmake/release/armeabi-v7a/CMakeFiles/3.6.0-rc2/CMakeSystem.cmake:6 (include):
  include could not find load file:

    /Users/***/Library/Android/sdk/ndk/23.0.7123448/build/cmake/android.toolchain.cmake
Call Stack (most recent call first):
  /Users/***/Developments/inkdrop/inkdrop-mobile/node_modules/react-native-quick-base64/android/.cxx/cmake/release/armeabi-v7a/CMakeFiles/CMakeTmp/CMakeLists.txt:2 (project)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- broken
CMake Error at /Users/***/Library/Android/sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler
  "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc"
  is not able to compile a simple test program.

  It fails with the following output:





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt


-- Configuring incomplete, errors occurred!
See also "/Users/***/Developments/inkdrop/inkdrop-mobile/node_modules/react-native-quick-base64/android/.cxx/cmake/release/armeabi-v7a/CMakeFiles/CMakeOutput.log".
See also "/Users/***/Developments/inkdrop/inkdrop-mobile/node_modules/react-native-quick-base64/android/.cxx/cmake/release/armeabi-v7a/CMakeFiles/CMakeError.log".
Enter fullscreen mode Exit fullscreen mode

It looks like that's because the NDK path has been changed, so /Users/***/Library/Android/sdk/ndk/23.0.7123448/build/cmake/android.toolchain.cmake does not exist anymore.

Running ./gradlew clean in android folder didn't clean them up.
So, I manually removed build/ and .cxx/ directories from the module directory:

rm -rf ./node_modules/react-native-quick-md5/android/.cxx ./node_modules/react-native-quick-base64/android/.cxx
Enter fullscreen mode Exit fullscreen mode

Then, I got another error like so:

$ ./gradlew :react-native-quick-base64:externalNativeBuildRelease

> Configure project :app

The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build.
This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify explicit versions, even if the versions are equal.
Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects.
If the parent project does not need the plugin, add 'apply false' to the plugin line.
See: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl
The Kotlin plugin was loaded in the following projects: ':react-native-aes-gcm-crypto', ':react-native-webview'

> Task :react-native-quick-base64:externalNativeBuildRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-quick-base64:externalNativeBuildRelease'.
> java.io.FileNotFoundException: /Users/***/Developments/inkdrop/inkdrop-mobile/node_modules/react-native-quick-base64/android/.cxx/cmake/release/armeabi-v7a/android_gradle_build.json (No such file or directory)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 4s
2 actionable tasks: 1 executed, 1 up-to-date
Enter fullscreen mode Exit fullscreen mode

Well, the following file does not exist:

/Users/***/Developments/inkdrop/inkdrop-mobile/node_modules/react-native-quick-base64/android/.cxx/cmake/release/armeabi-v7a/android_gradle_build.json
Enter fullscreen mode Exit fullscreen mode

That means that gradle doesn't recompile the C++ sources.

Run gradle with --rerun-tasks

Just running the gradle task does not recompile the C code.
You have to add --rerun-tasks option to do that.

./gradlew :react-native-quick-base64:externalNativeBuildRelease --rerun-tasks
Enter fullscreen mode Exit fullscreen mode

It solved the issue.

Follow me online

Top comments (0)