#include <string>
这个会提示找不到 string
根据 AS 自动提示就变成了
#include "../../../../../../../Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/string" class People { std::string getString(); };
但还是找不到 string ,是需要配置 NDK 的环境变量吗
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). # native-lib.cpp) people/People.cpp) 这个改成你的Peopei类相对地址,同步一下就行了
你把CMakeLists.txt 的 add_library 改成如上图所示,就行了。不过你会发现 nativate-lib.cpp 就报红了
最好还是配置一下目录,像我下边这样,所有的类都能正常引用了
aux_source_directory(. SOURCE_FILES) aux_source_directory(pople SOURCE_FILES_CORE) list(APPEND SOURCE_FILES ${SOURCE_FILES_CORE}) 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). ${SOURCE_FILES})
我又来自己回答了,我忘记在 add_library 中添加 People.cpp ,也就是在 CMakeLists.txt 中添加
add_library( people-lib SHARED people/People.cpp )
即可