Got error when I build the project like in the below. I tried so many things but never succeeded. I’m using m1 MacBook. Is this related with this error ?
[CXX1405] exception while building Json A problem occurred starting process ‘command ‘/Users/serhat/Library/Android/sdk/cmake/3.18.1/bin/cmake”in build.gradle:
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
and this is CmakeList.txt :
# For more information about using CMake with Android Studio,read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
3
Answers
I fixed this issue :
I’ve had a similar issue in the past when using 3.18.1 version of CMake. I’d suggest reinstalling the CMake SDK Tool from SDK Manager within Android Studio.
If it still seems to be referring to 3.18.1 after re-running it could be because a module is directly referring to it somewhere within the build.gradle file.
e.g.
I fixed this in expo-modules-core by removing the code below which seemed to be defaulting to an older version of CMake:
The solution for the CMake error while building your application might be to install Rosetta on your Mac. Rosetta is an emulation technology that allows programs designed for Intel processors to run on a Mac with an M1 or M2 chip. Some programs, such as CMake, may not be natively compatible with the M1 or M2 chip, so you need to install Rosetta to ensure that these programs work correctly.
To install Rosetta, you can use the following command:
Once you have installed Rosetta, try building your React Native application again. It should work without encountering the errors you mentioned.
I hope this solution helps you.