在AndroidStudio中往当前项目中添加JNI,其中有一步是创建CMakeLists.txt文件,很多博客说用复制某个成功运行的JNI项目的CMakeLists.txt文件来实现这一步,实际上是不行的,因为原来的cpp文件带来的依赖没办法依附在当前项目上。会报出以下错误:
Error computing CMake server result.
Check for working C compiler: /Users/donturner/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
Check for working C compiler: /Users/donturner/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: /Users/donturner/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++
Check for working CXX compiler: /Users/donturner/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Configuring done
追根揭底还是要从CMakeLists.txt文件的结构上入手,这一步的前提是新建好一个cpp文件
CMakeLists.txt中有个add_library:
add_library( # Sets the name of the library.
//cpp文件的名字或文件夹的名字
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
//该cpp文件的路径,有多少个cpp就写多少个)
然后再同步一下,AS就不会报错了