Skip to content

Commit 1e18d86

Browse files
farfromrefugclaude
andcommitted
feat(android): build only the requested abis in the bundled app build.gradle
`-PabiFilters=<abi>[,<abi>]` now narrows the native build down to those abis instead of being ignored, and an apk debug build splits so each abi gets its own package. `-PsplitEnabled` forces the split on for any build type; `-PonlyX86` keeps its old meaning and disables splitting. The property is what the CLI passes for the devices a run is about to deploy to, so this needs #6130 to be fully functional - on its own it only makes the property meaningful for anyone passing it through `--gradleArgs`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 508dd1e commit 1e18d86

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

vendor/gradle-app/app/build.gradle

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* -PandroidXMaterial=[androidx_material_version]
1919
* -PappPath=[app_path]
2020
* -PappResourcesPath=[app_resources_path]
21+
* -PabiFilters=[abi][,abi...] //build only these abis
22+
* -PsplitEnabled //one apk per abi
2123
*/
2224

2325
import groovy.io.FileType
@@ -50,6 +52,23 @@ if (onlyX86) {
5052
outLogger.withStyle(Style.Info).println "OnlyX86 build triggered."
5153
}
5254

55+
def DEFAULT_ABIS = ["x86", "x86_64", "armeabi-v7a", "arm64-v8a"]
56+
// -PabiFilters=<abi>[,<abi>] narrows the build down to those abis. The CLI passes the abis of the
57+
// devices it is about to deploy to, unless --no-filter-devices-arch was given.
58+
def requestedAbis = project.hasProperty("abiFilters")
59+
? project.findProperty("abiFilters").split(",").collect { it.trim() as String }.findAll { it }
60+
: null
61+
// splitting gives one apk per abi, so every device can be handed the one it needs. Only apk debug
62+
// builds split: a release artifact, like an app bundle, is meant to be shipped as a whole.
63+
def isDebugApkBuild = gradle.startParameter.taskNames.any { taskName ->
64+
def name = taskName.toLowerCase()
65+
name.startsWith("assemble") && name.endsWith("debug")
66+
}
67+
def splitEnabled = !onlyX86 && (project.hasProperty("splitEnabled") || (requestedAbis && isDebugApkBuild))
68+
if (requestedAbis) {
69+
outLogger.withStyle(Style.Info).println "Building abis: ${requestedAbis.join(", ")}${splitEnabled ? " (one apk each)" : ""}"
70+
}
71+
5372
//common
5473
def BUILD_TOOLS_PATH = "$rootDir/build-tools"
5574
def PASSED_TYPINGS_PATH = System.getenv("TNS_TYPESCRIPT_DECLARATIONS_PATH")
@@ -205,12 +224,25 @@ android {
205224
ndk {
206225
if (onlyX86) {
207226
abiFilters 'x86'
227+
} else if (splitEnabled) {
228+
// the splits block below decides which abi ends up in which apk
229+
} else if (requestedAbis) {
230+
abiFilters.addAll(requestedAbis)
208231
} else {
209-
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
232+
abiFilters.addAll(DEFAULT_ABIS)
210233
}
211234
}
212235
}
213236

237+
splits {
238+
abi {
239+
enable splitEnabled
240+
reset()
241+
include(*(requestedAbis ?: DEFAULT_ABIS))
242+
universalApk false
243+
}
244+
}
245+
214246
if (project.hasProperty("ndkVersion")) {
215247
ndkVersion project.ndkVersion
216248
}

0 commit comments

Comments
 (0)