我有来自供应商的.so文件,只支持“arm”。目前它对我的Android应用程序完全正常。不知何故,我想使用Android Studio模块分离实现,因此我可以按照本教程https://www.youtube.com/watch?v=1i4I-Nph-Cw将模块导出为Jar。
导出JAR时,构建过程会返回错误
/Users/zoom/android-ndk-r9d/toolchains/mipsel-linux-android-4.8/prebuilt/darwin-x86_64/bin/../lib/gcc/mipsel-linux-android/4.8/../../../../mipsel-linux-android/bin/ld: skipping incompatible src/main/jniLibs/armeabi/libremote_client.so when searching for -lremote_client
/Users/zoom/android-ndk-r9d/toolchains/mipsel-linux-android-4.8/prebuilt/darwin-x86_64/bin/../lib/gcc/mipsel-linux-android/4.8/../../../../mipsel-linux-android/bin/ld: cannot find -lremote_client
collect2: error: ld returned 1 exit status
:app:linkMipsDebugRemoteDesktopSharedLibrary FAILED
FAILURE: Build failed with an exception.
日志说gradle试图建立针对mips但由于不兼容的库而失败,因为我只有arm库。 我的问题如何跳过针对mips的构建过程?或者是否可以针对仅ARM架构?
的build.gradle
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "22.0.1"
defaultConfig.with {
//applicationId = "com.test.remote"
minSdkVersion.apiLevel = 19
targetSdkVersion.apiLevel = 21
//versionCode = 1
//versionName = "1.0"
}
}
android.ndk {
moduleName = "remote_client"
//CFlags += "-DANDROID_NDK"
CFlags += ['-std=c99', '-fstrict-aliasing']
ldLibs += ["log", "remoted_client"]
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.sources {
main {
jni {
source {
srcDir 'src/main/jni'
}
}
jniLibs {
source {
srcDir 'src/main/jniLibs'
}
}
}
}
android.productFlavors {
create("arm") {
ndk.with {
abiFilters += "armeabi"
ldFlags += "-Lsrc/main/jniLibs/armeabi"
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
}
task clearJar(type: Delete) {
delete 'mylib.jar'
}
task makeJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('release/')
include('classes.jar')
rename ('classes.jar', 'mylib.jar')
}
makeJar.dependsOn(clearJar, build)
答案 0 :(得分:2)
在Android SDK 26,NDK 15.2
上测试在文件app/build.gradle
上:
android {
defaultConfig {
ndk {
abiFilters 'arm64-v8a'
仅针对arm64-v8a
或所有当前未弃用的ARM目标构建:
abiFilters 'arm64-v8a', 'armeabi-v7a'
ABI目前位于:https://developer.android.com/ndk/guides/abis.html
在Ubuntu 17.10主机,Android Studio 3,Android SDK 26,NDK 15.2和Android 6.0.1设备上进行了测试。
示例项目on GitHub。
答案 1 :(得分:0)
只需将abiFilters
移至 android.ndk 部分:
model {
android.ndk {
moduleName = "remote_client"
CFlags += ['-std=c99', '-fstrict-aliasing']
ldLibs += ["log", "remoted_client"]
abiFilters = ['armeabi']
}
}
答案 2 :(得分:0)
最后我做到了。 这是禁用特定任务的示例。 在build.gradle
上添加此行tasks.getByPath(":app:linkMipsDebugRemoteDesktopSharedLibrary").enabled = false