Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions crates/tauri-cli/src/mobile/android/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,41 @@ fn generate_out_file(
Ok(None)
}
}

#[cfg(test)]
mod tests {
// Regression test for https://github.com/tauri-apps/tauri/issues/15884: the app build.gradle.kts
// template used to put `packaging { jniLibs.keepDebugSymbols.add(...) }` inside
// `buildTypes { getByName("debug") { ... } }`. `BuildType` has no `packaging` member, so Kotlin
// silently resolved that call against the outer `android {}` extension instead, applying the
// keep-symbols globs to every build type, including release. That caused release `.so` files to
// ship unstripped and made `ndk.debugSymbolLevel` extract nothing.
#[test]
fn debug_keep_debug_symbols_is_not_applied_to_every_build_type() {
let build_gradle = include_str!("../../../templates/mobile/android/app/build.gradle.kts");

let debug_block_start = build_gradle
.find(r#"getByName("debug")"#)
.expect("template should define a debug build type");
let release_block_start = build_gradle
.find(r#"getByName("release")"#)
.expect("template should define a release build type");
assert!(debug_block_start < release_block_start);

let debug_block = &build_gradle[debug_block_start..release_block_start];
assert!(
!debug_block.contains("packaging"),
"`getByName(\"debug\")` has no `packaging` block in AGP's DSL, so placing one there \
silently resolves against the outer `android {{}}` extension and leaks keepDebugSymbols \
into every build type, including release"
);

// `keepDebugSymbols` must instead be scoped to the debug variant through the variant API,
// which is the only DSL surface that actually restricts it to a single build type.
let variants_block = &build_gradle[build_gradle
.find("androidComponents")
.expect("template should scope keepDebugSymbols via androidComponents")..];
assert!(variants_block.contains(r#"selector().withBuildType("debug")"#));
assert!(variants_block.contains("keepDebugSymbols"));
}
}
18 changes: 13 additions & 5 deletions crates/tauri-cli/templates/mobile/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ android {
isDebuggable = true
isJniDebuggable = true
isMinifyEnabled = false
packaging {
{{#each abi-list}}
jniLibs.keepDebugSymbols.add("*/{{this}}/*.so")
{{/each}}
}
}
getByName("release") {
optimization {
Expand All @@ -63,6 +58,19 @@ android {
}
}

// `packaging` has no equivalent in the `buildTypes { getByName("debug") { ... } }` DSL, so a
// `packaging { ... }` block placed there silently resolves against the outer `android {}`
// extension instead and applies to every build type, including release. Scope it to the debug
// variant explicitly via the variant API so release libs are still stripped and
// `ndk.debugSymbolLevel` can extract debug metadata.
androidComponents {
onVariants(selector().withBuildType("debug")) { variant ->
{{#each abi-list}}
variant.packaging.jniLibs.keepDebugSymbols.add("*/{{this}}/*.so")
{{/each}}
}
}

kotlin {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
Expand Down