I've successfully implemented APK Splits so that separate APKs are generated for different ABIs.
However, for efficiency (and since I have no need for non-armeabi-v7a APKs in Debug), I would like to limit Debug builds to only generate armeabi-v7a APKs.
How can this be done?
One idea is with this:
abi {
enable true
reset()
include 'x86', 'armeabi-v7a', 'mips'
universalApk false
}
Maybe there is some way to set enable
based on the Build type?
You can try a variation on @Geralt_Encore's answer, which avoids the separate gradlew
command. In my case, I only cared to use APK splitting to reduce the released APK file size, and I wanted to do this entirely within Android Studio.
splits {
abi {
enable gradle.startParameter.taskNames.any { it.contains("Release") }
reset()
include 'x86', 'armeabi-v7a', 'mips'
universalApk false
}
}
From what I've seen, the Build | Generate Signed APK menu item in Android Studio generates the APK using the assembleRelease
Gradle target.
You can set enable
based on command line argument. I have solved kinda similar problem when I wanted to use splits only for the release version, but not for regular debug builds.
splits {
abi {
enable project.hasProperty('splitApks')
reset()
include 'x86', 'armeabi-v7a'
}
}
And then ./gradlew -PsplitApks assembleProdRelease
(prod is a flavor in my case).
I'm a bit late to this party, but having a problem with different flavors and tasks names, I've come with this:
ext.isRelease = { array ->
array.each { name ->
if (name.contains("Debug")) {
return false
}
}
return true
}
android {
...
splits {
abi {
enable isRelease(gradle.startParameter.taskNames)
reset()
include "x86_64", "x86", "arm64-v8a", "armeabi-v7a"
universalApk false
}
}
}
It's just a small update to Jeff P's answer but works well with different flavors and build configurations.
Update for @Jeff P's answer to make it more flexible based on app name and to support Android App Bundle (.aab) format
splits {
abi {
enable gradle.startParameter.taskNames.any { it.contains("Release") }
reset()
include 'x86', 'armeabi-v7a', 'mips'
universalApk false
}
}
来源:https://stackoverflow.com/questions/34592507/using-apk-splits-for-release-but-not-debug-build-type