AndroidStudio的JNI开发中遇到的一些问题
因为公司的项目中需要使用JNI,刚好借此机会学习一下JNI的使用,参考NDK-JNI实战教程(一) 在Android Studio运行第一个NDK程序 ,遇到了一些问题,在这里整理一下问题以及解决方案。
在通过命令行生成.h头文件之后rebuild提示
Error:Execution failed for task ':app:clean'. > Unable to delete directory build
clean以及rebuild都卡在这个问题上,最后根据提示手动删除相应的目录,重新编译解决
NDK integration is deprecated in the current plugin
在当前module的gradle.properties文件中,添加
android.useDeprecatedNdk=true
Error: Your project contains C++ files but it is not using a supported native build system.
解决方案参考:AS配置NDK外部工具
错误提示如下:
Error:Execution failed for task ':app:compileDebugNdk'.
> Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
- build成功之后,在
build/intermediates
目录下无法生成ndk目录以及对应的so动态库文件
将gradle中的
sourceSets ....
注销之后重新rebuild解决。
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jni/'] } }