Forked from bapspatil/build.gradle for APK splitting
Created
October 3, 2021 17:42
-
-
Save CypherpunkSamurai/9a49adb5c40fd68e83780e63a050c46f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
android { | |
... | |
... | |
defaultConfig { | |
... | |
versionCode 2000 | |
... | |
} | |
... | |
... | |
// APK splitting | |
splits { | |
abi { | |
// Enable APK splitting wrt architecture | |
enable true | |
// Reset the architectures for which you need to build the APKs for | |
reset() | |
// Include the architectures for which Gradle is building APKs | |
include 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' | |
// Set this to false if you don't want an APK that has native code for all architectures | |
universalApk false | |
} | |
} | |
// Assign codes to each architecture | |
project.ext.versionCodes = ['x86': 0, 'x86_64': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3] | |
// Add the architecture-specific codes above to base version code, i.e. the version code specified in the defaultConfig{} block | |
// Example: 2000 is the base version code -> 2000 (x86), 2001 (x86_64), 2002 (armeabi-v7a) & 2003 (arm64-v8a) would be the version codes for the generated APK files | |
android.applicationVariants.all { variant -> | |
variant.outputs.each { output -> | |
output.versionCodeOverride = project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1 + android.defaultConfig.versionCode | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment