問題描述
我想使用 Gradle 為 4 個不同的 Android CPU 處理器架構(armeabi armeabi-v7a x86 mips)構建 4 個單獨的 apk.
I want to build 4 separate apks for 4 different Android CPU processor architectures (armeabi armeabi-v7a x86 mips) using Gradle.
我在 libs 文件夾中有為 4 個 CPU 架構構建的原生 OpenCV 庫.
I have native OpenCV libraries built for 4 CPU architectures in the libs folder.
libs
-armeabi
-armeabi-v7a
-x86
-mips
我希望每個 apk 只包含對應正確 CPU 架構的 OpenCV 庫.
I want to each apk only contains the OpenCV library corresponding to the correct CPU architecture.
當前構建腳本如下:
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':workspace:OpenCV4Android:sdk:java')
}
android {
compileSdkVersion 11
buildToolsVersion "18.1.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
flavorGroups "abi", "version"
productFlavors {
x86 {
flavorGroup "abi"
}
arm {
flavorGroup "abi"
}
mips {
flavorGroup "abi"
}
}
}
}
有人可以幫我解決這個問題嗎?
Can someone help me to resolve this please?
干杯,
推薦答案
從 Android Gradle 插件版本 13 開始,您現在可以使用新的拆分"機制生成單獨的 APK.你可以閱讀它這里.
As of Android Gradle Plugin version 13 you can now generate seperate APK's using the new "split" mechanism. You can read about it here.
放置 .so 文件的默認文件結構是:
The default file structure for placing your .so files is:
src
-main
-jniLibs
-armeabi
-arm.so
-armeabi-v7a
-armv7.so
-x86
-x86.so
-mips
-mips.so
請注意,.so 文件的名稱并不重要,只要它具有 .so 擴展名.
Note that the name of the .so file is unimportant as long as it has the .so extension.
然后在你的 Gradle 構建文件中:
Then in your Gradle build file:
android {
...
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a', 'mips', 'armeabi'
universalApk false
}
}
}
和
// map for the version code
ext.versionCodes = ['armeabi-v7a':1, mips:2, x86:3]
import com.android.build.OutputFile
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) * 1000000 + android.defaultConfig.versionCode
}
}
請注意,上面 ext.versionCodes 中的版本代碼在很大程度上是無關緊要的,這是為每個 ABI 類型添加唯一的偏移量,因此版本代碼不會沖突.
Note that the version codes above in ext.versionCodes are largely irrelevant, this is here to add a unique offset for each ABI type so version codes do not clash.
這篇關于Gradle android 為不同的處理器架構構建的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!