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.
Related
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'
}
}
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 have in build.gradle Android splits:
splits {
abi {
enable true
reset()
include 'x86', 'mips', 'armeabi-v7a', 'armeabi'
universalApk false
}
}
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
versionCodes.get(output.getFilter(OutputFile.ABI), 0) * 1000000 + android.defaultConfig.versionCode
}
}
After update of Robolectric to 3.0 I become path error:
build/intermediates/manifests/full/debug/AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml
because I in build/intermediates/manifests/full/ have 4 splits folders
armeabi/ armeabi-v7a/ mips/ x86/
How can i set in Robolectric config or in gradle configuration, that I have splits?
Thank you
UPDATE:
In all my classes I have following configuration:
#RunWith(RobolectricGradleTestRunner.class)
#Config(sdk = 21, manifest = "../application/AndroidManifest.xml", constants = BuildConfig.class)
I think the easiest way will just be to point it to your x86/AndroidManifest.xml
You can specify this using the manifest key in your #Config, e.g.
#Config(manifest="path-here")
Since you will need this for every test, you might also consider creating a properties file. For more details on this, the docs are here
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