[英]How can I add a static library to Android NDK using the build.gradle file?
I'm trying to learn to use the NDK in AndroidStudio, and I'd like to import the "android_native_app_glue" file used in the "native-activity" sample, so that I have a framework for basic functions like the display, touch, etc. In the sample, it loads the library with this line in the android.mk file: 我正在尝试学习在AndroidStudio中使用NDK,并且我想导入“native-activity”示例中使用的“android_native_app_glue”文件,这样我就有了一个基本功能的框架,如显示,触摸,在示例中,它使用android.mk文件中的这一行加载库:
LOCAL_STATIC_LIBRARIES := android_native_app_glue
and then imports it in "main.c" simply with: 然后使用以下命令在“main.c”中导入它:
#include <android_native_app_glue.h>
But in AndroidStudio, as far as I can tell from experimenting with it, it doesn't use the android.mk file at all and instead uses the build.gradle file to do all the same functions instead. 但是在AndroidStudio中,据我尝试使用它,它根本不使用android.mk文件而是使用build.gradle文件来代替所有相同的函数。 So, for example, to replace
LOCAL_LDLIBS := ...
in the android.mk, I used ldLibs = ...
in the build.gradle. 因此,例如,要在android.mk中替换
LOCAL_LDLIBS := ...
,我在build.gradle中使用了ldLibs = ...
What gradle code replaces LOCAL_STATIC_LIBRARIES
? 什么gradle代码替换了
LOCAL_STATIC_LIBRARIES
?
Is there also a resource somewhere that explains, in general, how to translate from android.mk to build.gradle? 在某些地方是否还有一个资源可以解释如何从android.mk转换为build.gradle?
if you really want to make it work without Makefiles, you can copy and paste ndk\\sources\\android\\native_app_glue\\android_native_app_glue.(c|h)
into your jni folder and add android
to your ldLibs . 如果你真的想让它在没有Makefiles的情况下工作,你可以将
ndk\\sources\\android\\native_app_glue\\android_native_app_glue.(c|h)
复制并粘贴到你的jni文件夹中并将android
添加到你的ldLibs 。
Else, you can still rely on classic Makefiles, by deactivating the default call to ndk-build, and making gradle use your libs from the libs
directory: 另外,您仍然可以依赖经典的Makefile,通过停用对ndk-build的默认调用,并使gradle使用
libs
目录中的libs
:
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
In that case you'll have to call ndk-build
yourself, but you can also make gradle call it for you: 在这种情况下,你必须自己调用
ndk-build
,但你也可以让gradle为你调用它:
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
} else {
commandLine 'ndk-build', '-C', file('src/main').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.