fix(cli): scope Android template's keepDebugSymbols to the debug build type only - #15945
Open
2akouwu wants to merge 1 commit into
Open
fix(cli): scope Android template's keepDebugSymbols to the debug build type only#159452akouwu wants to merge 1 commit into
2akouwu wants to merge 1 commit into
Conversation
The generated app/build.gradle.kts placed `packaging { jniLibs.keepDebugSymbols.add(...) }` inside `buildTypes { getByName("debug") { ... } }`. AGP's `BuildType` DSL has no `packaging` block, so Kotlin silently resolved the call against the outer `android {}` extension instead, applying the keep-symbols globs to every build type, including release. This shipped unstripped `.so` files in release builds and made `ndk.debugSymbolLevel` unable to produce debug symbols metadata.
Scope the globs to the debug variant explicitly via `androidComponents { onVariants(selector().withBuildType("debug")) { ... } }`, the only DSL surface that actually restricts this setting to a single build type.
Add a regression test asserting the debug build type block stays free of `packaging`/`keepDebugSymbols` and that they instead live in a debug-scoped `androidComponents` variant block.
Fixes tauri-apps#15884.
Signed-off-by: ulofiai <309826581+ulofiai@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
The generated
app/build.gradle.ktsin the mobile Android template wrote:buildTypes { getByName("debug") { ... packaging { jniLibs.keepDebugSymbols.add("*/arm64-v8a/*.so") ... } }AGP's Kotlin
BuildTypeDSL (com.android.build.api.dsl.ApplicationBuildType) has nopackagingmember. Because Kotlin resolves an unmatched receiver against the next enclosing scope, thatpackaging { ... }call silently binds to the outerandroid {}extension'spackagingproperty instead of anything debug-specific. The keep-symbols globs therefore applied to every build type, including release:.sofiles shipped unstripped, since AGP'sstripReleaseDebugSymbolstask matched the glob and copied the lib verbatim instead of runningllvm-strip.ndk.debugSymbolLevelproduced no debug-symbols bundle metadata, becauseExtractNativeDebugMetadataTaskcompares byte lengths against the (no-op) strip output and sees them as already stripped.Both failures are silent — no warning or error is emitted anywhere in the build.
Why this fix
I used the fix the issue itself verified working (AGP 8.11.0 / Gradle 8.14.3): move the keep-symbols globs out of the
buildTypesDSL entirely and apply them through the variant API, which is the only surface that actually scopes a setting to a single build type:androidComponents { onVariants(selector().withBuildType("debug")) { variant -> variant.packaging.jniLibs.keepDebugSymbols.add("*/arm64-v8a/*.so") ... } }I considered instead moving the
packaging {}call to sit next tocompileOptions/buildFeaturesinsideandroid {}with some kind of build-type conditional, but the DSL doesn't offer a clean way to conditionally scope glob entries there without re-implementing whatandroidComponents.onVariantsalready does — so the variant-API approach is both the smallest change and the technically correct one. I kept the existing{{#each abi-list}}Handlebars loop as-is, just changed the surrounding Kotlin scaffolding, to keep the diff minimal.The issue also names a second affected template in
cargo-mobile2(templates/platforms/android-studio/app/build.gradle.kts.hbs), but that file lives in the separatetauri-apps/cargo-mobile2repository and isn't part of this repo, so it's out of scope here.Testing
Added
debug_keep_debug_symbols_is_not_applied_to_every_build_typeincrates/tauri-cli/src/mobile/android/project.rs, which loads the real (unrendered) template viainclude_str!and asserts:getByName("debug") { ... }block (up togetByName("release")) no longer contains apackagingblock, guarding against this mis-scoping regressing, andandroidComponents { ... }block exists that scopes toselector().withBuildType("debug")and containskeepDebugSymbols.This test fails against the pre-fix template (where
packaging/keepDebugSymbolssit inside the debug build type and noandroidComponentsblock exists) and passes with the fix applied. I did not runcargo testin this environment since it requires network access to fetch crate dependencies that isn't available here, but the test only does string slicing/containschecks against a&'static strproduced byinclude_str!, so it doesn't depend on any Android/Gradle toolchain — I traced the logic by hand against both the old and new template content to confirm the assertions land as expected on each.Fixes #15884.