我正在使用Android Studio 1.5.1 Gradle版本2.8。 Gradle实验插件v0.4.0 我有一个包含本机C代码和java代码的库。我正在生成一个库CoreLib-fat-release.aar,其中包含适用于所有体系结构的本机库(libcore.so) - arm64-v8a,armeabi,armeabi-v7a,mips,mips64,x86,x86-64。 我有第二个库,取决于我的核心库。我将Core库作为共享库。
在第二个库gradle文件中:
jni {
dependencies {
project ":CoreLib" buildType "release" productFlavor "fat" linkage "shared"
}
}
它能够正确构建,但是当我打开并看到第二个库aar文件时,我在所有架构文件夹中都看不到libcore.so。
例如: SecondLibrary-fat-release.aar => SecondLibrary脂肪释放拉链 在SecondLibrary-fat-release / jni文件夹中,只有x86和x86_64文件夹包含libcore.so文件。其他文件夹(arm64-v8a,armeabi,armeabi-v7a,mips,mips64)不包含libcore.so文件。
由于这个原因,如果我在64位设备中使用我的第二个库,它会抱怨UnSatisfiedLink错误说找到32位库而不是64位。
HEre是我的第二个库的build.gradle:
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 21
buildToolsVersion = "23.0.2"
defaultConfig.with {
minSdkVersion.apiLevel = 21
targetSdkVersion.apiLevel = 21
testInstrumentationRunner = "android.test.InstrumentationTestRunner"
}
lintOptions.with {
abortOnError = false
}
}
android.ndk {
moduleName = "secondlibrary
cppFlags.addAll("-I${file(folder_path)}".toString(),
"-I${file(sourcesDir +folder1)}".toString(),
"-I${file(sourcesDir +folder2)}".toString(),
)
cppFlags.add("-frtti")
cppFlags.add("-fexceptions")
CFlags.addAll("-I${file(folder_path)}".toString(),
"-I${file(sourcesDir +folder1)}".toString(),
"-I${file(sourcesDir +folder2)}".toString(),
)
CFlags.add("-O3")
CFlags.add("-funroll-loops")
CFlags.add("-Wall")
ldLibs.addAll(["android", "log", "stdc++", "c", "m", "z", "EGL", "GLESv2"])
stl = "gnustl_shared"
}
// jni is the default dir; config this if yours is in different directory
android.sources {
androidTest {
java {
source {
srcDirs '../test_sources_path/src'
}
}
}
main {
manifest {
source {
srcDirs '.'
}
}
java {
source {
srcDir "src"
}
}
jni {
dependencies {
project ":CoreLib" buildType "release" productFlavor "fat" linkage "shared"
}
source {
srcDirs = ["jni",
path1,
path2,
"libcore.so"]
}
}
jniLibs {
dependencies {
library file(path_to_binaries + "libcore.so") abi "armeabi"
library file(path_to_binaries + "libcore.so") abi "x86"
library file(path_to_binaries + "libcore.so") abi "armeabi-v7a"
library file(path_to_binaries + "libcore.so") abi "mips"
library file(path_to_binaries + "libcore.so") abi "x86_64"
library file(path_to_binaries + "libcore.so") abi "arm64-v8a"
library file(path_to_binaries + "libcore.so") abi "mips64"
}
}
}
}
android.productFlavors {
create("fat")
}
repositories {
libs(PrebuiltLibraries) {
CoreLib {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(path_to_binaries + "${targetPlatform.getName()}/libcore.so")
}
}
}
}
}
dependencies {
compile project(':CoreLib-fat-release')
}
注意:如果我将CoreLib链接作为静态'而不是共享',然后所有libcore.so文件都被正确复制到所有文件夹。
如果这是编程问题或实验插件中的错误,请告诉我。如果您有其他选择,请建议我?谢谢。
答案 0 :(得分:0)
通过执行以下操作解决了此问题:
build.gradle所需的更改:
我们可以删除
jniLibs {
dependencies {
library file(path_to_binaries + "libcore.so") abi "armeabi"
library file(path_to_binaries + "libcore.so") abi "x86"
library file(path_to_binaries + "libcore.so") abi "armeabi-v7a"
library file(path_to_binaries + "libcore.so") abi "mips"
library file(path_to_binaries + "libcore.so") abi "x86_64"
library file(path_to_binaries + "libcore.so") abi "arm64-v8a"
library file(path_to_binaries + "libcore.so") abi "mips64"
}
}
因为这段代码足够了:
repositories {
libs(PrebuiltLibraries) {
CoreLib {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(path_to_binaries + "${targetPlatform.getName()}/libcore.so")
}
}
}