如何使用 gradle 0.7+ 将 .so 文件添加到 android 库项目 [英] How can I add .so files to an android library project using gradle 0.7+
问题描述
项目结构:
App 项目 --> 依赖于 Library 项目
App project --> depends on Library project
图书馆项目有一个用于编译 jni 库的文件夹
Library Project has a folder for the compiled jni libs
jniLibs.srcDirs = ['libs']
我已经尝试按照示例应用将以下内容添加到 build.gradle 的 android 元素中 https://android.googlesource.com/platform/tools/build/+/2e1f7810edd76d92cee8d3e06bc4dec0c288adea/tests/ndkSanAngeles/build.gradle 但是android库项目不支持productFlavours和as这样的组装失败,在项目中找不到方法 productFlavors() 用于参数 [dghdhd]"
And I've tried adding the following to the android element of the build.gradle as per the example app https://android.googlesource.com/platform/tools/build/+/2e1f7810edd76d92cee8d3e06bc4dec0c288adea/tests/ndkSanAngeles/build.gradle however android library projects do not support productFlavours and as such the assemble fails with "Could not find method productFlavors() for arguments [dghdhd] on project"
productFlavors {
x86 {
ndk {
abiFilter "x86"
}
}
arm {
ndk {
abiFilters "armeabi-v7a", "armeabi"
}
}
}
有没有办法为 android 库项目添加 ndk 支持?
Is there a way to add ndk support to an android library project?
推荐答案
最终我不需要使用产品风味.
In the end I didnt need to use product flavours.
对于图书馆项目,我添加了以下内容:
For the library project I added the following:
android {
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
libs 文件夹中有一个名为armeabi-v7a"的文件夹,因为这是我唯一的目标,所以它很有效.
The libs folder had a folder inside called "armeabi-v7a" and as this is my only target it worked a treat.
ndk 文件 (.so) 被传播到使用 android 库项目的 android 项目中.
The ndk files (.so) are propagated into the android project that is using the android library project.
这篇关于如何使用 gradle 0.7+ 将 .so 文件添加到 android 库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!