关于android ndk:使用Gradle 2.2.1 加载共享库
Loading shared libraries with Gradle 2.2.1
我正在尝试在我的 Android 应用程序中使用共享库 libavcodec-56.so,但我找不到方法。我正在使用 Gradle 2.2.1 和 Android Studio 1.0。到目前为止我所做的如下:
-我使用 NDK 工具链从源代码构建 libavcodec-56.so。
-我将 libavcodec-56.so 复制到 src/main/jniLibs/armeabi
-我能够在项目中创建一个 .c 文件并使用 private native void nameOfTheNativeMethod()
与 java 文件进行通信
-我可以加载一些外部库,例如 ldLibs"m"
但是,如果我尝试使用 #include <libavcodec/avcodec.h> 我会收到错误
|
1
2 |
No such file or directory
#include <libavcodec/avcodec.h> |
我的 gradle 文件看起来像:
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
apply plugin: 'com.android.library'
android { defaultConfig { sourceSets.main {
buildTypes { dependencies { } |
有什么想法吗?
提前致谢
当前对 gradle android 插件的 NDK 支持不完整,现已弃用。本地本地库之间不能有本地依赖关系。
现在使用 gradle 的唯一解决方案是直接使用 ndk-build 和你自己的 Makefile 来生成你所有的库,用这样的 build.gradle 文件:
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.library' android { defaultConfig { sourceSets.main { buildTypes { // call regular ndk-build(.cmd) script from app directory tasks.withType(JavaCompile) { dependencies { } |