This is my app's build.gradle:
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk true
}
}
Every time build APK, I get 3 APKs.
But, I only use app-universal-release.apk for my team.
Can I delete include "x86", "armeabi-v7a", for less build time?
Also, can i delete splits{...} ?
I add a flag to my gradle, and pass the flag by ./gradlew assembleDebug -Pflag=true.
android {
if (flag.toBoolean()) {
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk true
}
}
} else {
defaultConfig.ndk.abiFilters 'x86', 'armeabi-v7a'
}
}
Related
when i try to install from adb it gives me this error
Installation failed with message INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113
this will happen only in oreo OS.
i also add this in Build.gradle
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk true
}
}
but this is not work.
Try to find out which ABIS you were missing from your project.
And then include them as
include 'arm', 'arm-v7a', 'arm64', 'mips', 'x86', 'x86_64', 'armeabi-v7a'
Secondly, check if you really require universalApk, you can either use minsdkversion and targetsdkversion which will cover your whole range.
I am attempting to build all ABIs for my project but would only like to package a subset of them into my app. For example, I would like to build "x86", "x86_64", "armeabi-v7a" and "arm64-v8a" but only package "x86" (for example).
Reading this document (https://developer.android.com/studio/projects/gradle-external-native-builds.html#jniLibs) under section "Specify ABIs", it seems very possible using the snippet they provided as an example. However, this does not seem to be working for me.
My code snippet is as follows.
android {
defaultConfig {
ndk {
abiFilters 'armeabi-v7a'
}
externalNativeBuild {
cmake {
abiFilters 'armeabi-v7a', 'x86'
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
In the snippet above, from my understanding of the document, it should build both armeabi-v7a and x86, but only package armeabi-v7a in my APK. This is not working though.
I am using Android plugin 3.1.0 and NDK 16.1.4479499
what you are looking for, is controlled by splits.
splits {
abi {
enable true
reset()
include 'armeabi-v7a'
universalApk false //don't generate an additional APK that contains all the ABIs
}
}
I need to do some build operations only during release build to speed up the routine debug build. How to test, if I'm doing a release build in the build.gradle script?
splits {
abi {
enable /* CONDITION HERE -> */ true
reset()
include 'x86', 'armeabi-v7a', 'mips'
universalApk true
}
}
I found an example here, but I don't want to set build property, I prefer it to be automatic.
Please try:
splits {
abi {
if (project.gradle.startParameter.taskNames.any { it.toLowerCase().contains('release') }) {
enable true
reset()
include 'x86', 'armeabi-v7a', 'mips'
universalApk true
} else {
enable true
reset()
include 'armeabi-v7a'
universalApk false
}
}
}
However, mind the fact that this configuration doesn't take task dependencies into account.
What I mean is a task may depend on some release task and even if it isn't passed via command line it might be executed.
I want to add ndk.abiFilters property in gradle.properties file. Now I've this property inside build.gradle.
Here is part of my build.gradle
buildTypes {
debug {
ndk {
abiFilters "x86", "armeabi-v7a", "armeabi"
//abiFilters ABI_FILTERS
}
}
}
Here's part of my gradle.properties file
ABI_FILTERS = "x86", "armeabi-v7a", "armeabi"
Problem is that String from gradle.properties is not correctly converted for use with abiFilters. I tried many variants but with no luck. What is the correct way how to do this correctly? Thank you for help.
In gradle.properties you can have for example:
ABI_FILTERS=armeabi-v7a;x86 //delimiter can be anything (change below)
Then in build.gradle there is (for example in debug buildType section):
ndk {
abiFilters = []
abiFilters.addAll(ABI_FILTERS.split(';').collect{it as String})
}
Now each developer can choose independetly abi for his current testing device (gradle.properties is in .gitignore).
Thanks Igor Ganapolsky for starting hint.
Following works with Gradle 2.3:
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
gradle.properties file
ABI_FILTERS = ["armeabi", "x86"]
build.gradle file
ndk {
abiFilters = []
abiFilters.addAll(ABI_FILTERS)
}
Use this:
flavorDimensions "abi"
productFlavors {
arm7 {
dimension "abi"
ndk.abiFilters 'armeabi-v7a'
}
x86 {
dimension "abi"
ndk.abiFilters 'x86'
}
}
You can see an example of this setting in the Google samples for NDK: https://github.com/android/ndk-samples/blob/8132651aba8db36b14e0d0461c7cb46d3778f99c/other-builds/ndkbuild/hello-neon/app/build.gradle
This can also be done for flutter.
Add:
android{
buildTypes{
debug {
ndk {
abiFilters 'arm64-v8a'
}
}
}
}
to android\app\build.gradle. That works to remove the x86 libflutter.so libraries from the debug builds and shortens installation time. Works for gradle 7.2
I want use "splits" by "abi", but only for release build. Is this possible? I try use ext variable and variable by "def" also which is set to false by default. This variable is set to true in buildTypes for releaseWithLog (and release).
But I don't know how Gradle work, because when I add writeln() with test message to "debug", "releaseWithLog" and "release" and run build, all messages are in output, so this confirms me that variable "splitsEnabled" is set to true though I build for debug - and I expect value "false" for debug (and not using splits for debug therefore).
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
ext {
splitsEnabled = false
}
defaultConfig {
...
}
buildTypes {
debug {
...
}
releaseWithLog {
...
splitsEnabled = true
}
release.initWith(releaseWithLog)
release {
...
}
}
...
splits {
abi {
println(splitsEnabled)
enable splitsEnabled
reset()
include 'x86', 'armeabi-v7a', 'armeabi'
exclude 'x86_64', 'mips64', 'arm64-v8a', 'mips'
universalApk true
}
}
...
You can solve this easily with a command line argument to Gradle, or the "Script parameters:" field for a Gradle task in Android Studio. I used -P to define 'dbgBld' symbol and used it for debug builds, e.g.:
gradle -PdbgBld installDebug
My build.gradle file has the following splits command:
splits {
abi {
enable !project.hasProperty('dbgBld')
reset()
include 'armeabi', 'armeabi-v7a', 'x86', 'mips'
universalApk true
}
}
Now to build release I use:
gradle assembleRelease
The 'dbgBld' symbol is not defined, so the splits enable field resolves to true and I get 5 APK files. When building for debugging, the -PdbgBld is already saved in my Android Studio configuration and I get only one "fat" APK for debugging, which results in much faster debug builds.
Greg