Android studio2.2 构建C/C++工程
AS2.2 版本对于JNI有了很好的支持,可以在新建工程的时候直接 import C++,一直下一步就可以得到一个支持JNI开发的工程。

新建好的工程:
会帮我们新建好两个文件,native-lib.cpp 和CMakeLists.txt

当我第一次创建工程的时候,出现了如下错误:
错误日志
External Native Build Issues
Build command failed.
Error while executing 'D:\sdk\cmake\3.6.3155560\bin\cmake.exe' with arguments {-HE:\andriodStudioworkspace\MyJniHello\app -BE:\andriodStudioworkspace\MyJniHello\app\.externalNativeBuild\cmake\debug\armeabi -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi -DANDROID_NDK=D:\sdk\ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=E:\andriodStudioworkspace\MyJniHello\app\build\intermediates\cmake\debug\obj\armeabi -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=D:\sdk\cmake\3.6.3155560\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=D:\sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=19 -DCMAKE_CXX_FLAGS=}
-- Configuring incomplete, errors occurred!.............
错误原因:工程中包含的NDK包不完整所致,这时候在网上重新下载一个NDK完整包就可以解决问题
下载地址:
NDK 13b
https://dl.google.com/android/repository/android-ndk-r13b-windows-x86.zip
https://dl.google.com/android/repository/android-ndk-r13b-windows-x86_64.zip
https://dl.google.com/android/repository/android-ndk-r13b-darwin-x86_64.zip
https://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip
如果是不用原来的系统自动生成的文件native-lib.cpp来开发,可以自己新创建一个C文件

但是需要配置相应的 CMakeLists.txt文件,改成相应文件名称

系统给我新建的本地方法和静态代码块中加载本地方法


下面就可以愉快的进行JNI开发了(第一次写文章,有些粗糙)。
传送门:
网友评论