[Reland] Don't strip symbols from libapp.so on android by default#181275
[Reland] Don't strip symbols from libapp.so on android by default#181275auto-submit[bot] merged 8 commits intoflutter:masterfrom
libapp.so on android by default#181275Conversation
| } | ||
| } | ||
| } | ||
| // Copy the native assets created by build.dart and placed here by flutter assemble. |
There was a problem hiding this comment.
Native assets are now copied by copyJniLibsTask to the jniLibs folder, which is registered as a source set.
There was a problem hiding this comment.
I know it is somewhat orthogonal question, but did we make sure that native assets are also unstripped on Android by default (so that they could also be correctly picked up when publishing)?
cc @dcharkes
There was a problem hiding this comment.
Currently we don't do any stripping for native assets, but maybe we should? I've filed:
|
re requesting your review @mraleph, as you were on the original pr (many months ago) |
There was a problem hiding this comment.
Code Review
This pull request modifies the Android build process to delegate symbol stripping of libapp.so to the Android Gradle Plugin (AGP). This is accomplished by no longer passing the --strip flag to gen_snapshot for Android targets and adjusting the Flutter Gradle Plugin to package .so files directly for AGP to process, rather than within a JAR file. The changes also encompass necessary updates to tests and validation checks to ensure that debug symbols for libapp.so are handled correctly. My review includes suggestions to enhance code style and readability.
| val abi: String? = FlutterPluginConstants.PLATFORM_ARCH_MAP[targetPlatform] | ||
| from("${flutterCompileTask.intermediateDir}/$abi") { | ||
| include("*.so") | ||
| // Move `app.so` to `lib/<abi>/libapp.so` | ||
| rename { filename: String -> "lib/$abi/lib$filename" } | ||
| rename { filename: String -> "lib$filename" } | ||
| into(abi!!) | ||
| } | ||
| // Copy the native assets created by build.dart and placed in build/native_assets by flutter assemble. | ||
| // The `$project.layout.buildDirectory` is '.android/Flutter/build/' instead of 'build/'. | ||
| val buildDir = | ||
| "${FlutterPluginUtils.getFlutterSourceDirectory(project)}/build" | ||
| val nativeAssetsDir = | ||
| "$buildDir/native_assets/android/jniLibs/lib" | ||
| from("$nativeAssetsDir/$abi") { | ||
| include("*.so") | ||
| rename { filename: String -> "lib/$abi/$filename" } | ||
| into(abi!!) | ||
| } |
There was a problem hiding this comment.
To improve null safety and avoid potential runtime exceptions, it's better to explicitly handle the nullable abi variable rather than using the non-null assertion operator (!!). A null check with a warning for unsupported platforms would make the code more robust.
val abi = FlutterPluginConstants.PLATFORM_ARCH_MAP[targetPlatform]
if (abi == null) {
project.logger.warn("Unsupported platform: $targetPlatform. Skipping.")
return@forEach
}
from("${flutterCompileTask.intermediateDir}/$abi") {
include("*.so")
rename { filename: String -> "lib$filename" }
into(abi)
}
// Copy the native assets created by build.dart and placed in build/native_assets by flutter assemble.
val buildDir =
"${FlutterPluginUtils.getFlutterSourceDirectory(project)}/build"
val nativeAssetsDir =
"$buildDir/native_assets/android/jniLibs/lib"
from("$nativeAssetsDir/$abi") {
include("*.so")
into(abi)
}There was a problem hiding this comment.
+1 to !! being risky to use. Are you sure you want to crash here?
There was a problem hiding this comment.
Hmm I had assumed the line that existed before would crash, but string interpolation allows null in kotlin (it just inserts the string "null") so I was wrong about that.
I made both of these cases behave similarly, where we use the string "null" if abi is null (the into() method in the closure doesn't accept a String?)
| if (!(result.stdout.contains('libflutter.so.sym') || | ||
| result.stdout.contains('libflutter.so.dbg'))) { | ||
| _logger.printTrace( | ||
| 'libflutter.so.sym or libflutter.so.dbg not present when checking final appbundle for debug symbols.', | ||
| ); | ||
| return false; | ||
| } | ||
|
|
||
| _logger.printTrace( | ||
| 'libflutter.so.sym or libflutter.so.dbg not present when checking final appbundle for debug symbols.', | ||
| ); | ||
| return false; | ||
| if (!(result.stdout.contains('libapp.so.sym') || result.stdout.contains('libapp.so.dbg'))) { | ||
| _logger.printTrace( | ||
| 'libapp.so.sym or libapp.so.dbg not present when checking final appbundle for debug symbols.', | ||
| ); | ||
| return false; | ||
| } | ||
|
|
||
| return true; |
There was a problem hiding this comment.
The logic for checking debug symbols can be made more readable by extracting the boolean conditions into local variables. This would clarify the intent of each check.
final bool hasFlutterSymbols = result.stdout.contains('libflutter.so.sym') ||
result.stdout.contains('libflutter.so.dbg');
if (!hasFlutterSymbols) {
_logger.printTrace(
'libflutter.so.sym or libflutter.so.dbg not present when checking final appbundle for debug symbols.',
);
return false;
}
final bool hasAppSymbols = result.stdout.contains('libapp.so.sym') || result.stdout.contains('libapp.so.dbg');
if (!hasAppSymbols) {
_logger.printTrace(
'libapp.so.sym or libapp.so.dbg not present when checking final appbundle for debug symbols.',
);
return false;
}
return true;| final bool targetingAndroidPlatform = | ||
| platform == TargetPlatform.android || | ||
| platform == TargetPlatform.android_arm || | ||
| platform == TargetPlatform.android_arm64 || | ||
| platform == TargetPlatform.android_x64; |
There was a problem hiding this comment.
For better readability and maintainability, consider using a Set with the contains method for the targetingAndroidPlatform check, instead of multiple || operators.
| final bool targetingAndroidPlatform = | |
| platform == TargetPlatform.android || | |
| platform == TargetPlatform.android_arm || | |
| platform == TargetPlatform.android_arm64 || | |
| platform == TargetPlatform.android_x64; | |
| final bool targetingAndroidPlatform = const <TargetPlatform>{ | |
| TargetPlatform.android, | |
| TargetPlatform.android_arm, | |
| TargetPlatform.android_arm64, | |
| TargetPlatform.android_x64, | |
| }.contains(platform); |
| packJniLibsTask | ||
| }) | ||
| ) | ||
| val mergeJniLibsTaskName = "merge${FlutterPluginUtils.capitalize(variant.name)}JniLibFolders" |
There was a problem hiding this comment.
Non blocking but this task will need to migrated to the new style with inputs and outputs for agp 9.
| _logger.printTrace('Will strip AOT snapshot manually after build and dSYM generation.'); | ||
| } | ||
| } else if (targetingAndroidPlatform) { | ||
| stripAfterBuild = false; |
There was a problem hiding this comment.
uber nit: comment before setting the variable. (non blocking)
|
autosubmit label was removed for flutter/flutter/181275, because - The status or check suite Windows tool_integration_tests_2_9 has failed. Please fix the issues identified (or deflake) before re-applying this label. |
flutter/flutter@7165649...dfd92b7 2026-01-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fixes metal vec3 uniform padding (#181340)" (flutter/flutter#181552) 2026-01-27 [email protected] Change update_engine_version documenation (flutter/flutter#181508) 2026-01-27 [email protected] Roll Packages from e712bfa to e37af11 (7 revisions) (flutter/flutter#181544) 2026-01-27 [email protected] Roll FreeType to 2.14.1 (flutter/flutter#181428) 2026-01-27 [email protected] Roll Skia from 566d202962d3 to c2754838b077 (3 revisions) (flutter/flutter#181536) 2026-01-27 [email protected] [Material] modernize time picker components with Dart 3 switch expressions (flutter/flutter#181356) 2026-01-27 [email protected] Roll Skia from 55a87b50a368 to 566d202962d3 (1 revision) (flutter/flutter#181528) 2026-01-27 [email protected] Roll Dart SDK from f55d4538469a to 4c7cb0a1d07d (2 revisions) (flutter/flutter#181526) 2026-01-27 [email protected] Replace `pub run` mentions with `dart run` (flutter/flutter#181317) 2026-01-27 [email protected] Roll Skia from 1a15ed6b17f2 to 55a87b50a368 (1 revision) (flutter/flutter#181523) 2026-01-27 [email protected] Marks linux_chrome_dev_mode to be unflaky (flutter/flutter#181352) 2026-01-27 [email protected] Roll Skia from f2c1aa140b79 to 1a15ed6b17f2 (2 revisions) (flutter/flutter#181514) 2026-01-27 [email protected] Fix Range Slider issue where indescrete ranges lead to out of range r… (flutter/flutter#181082) 2026-01-26 [email protected] Roll Dart SDK from ba23b5ed0a97 to f55d4538469a (2 revisions) (flutter/flutter#181512) 2026-01-26 [email protected] Add `alignment` to `SizeTransition` (flutter/flutter#177895) 2026-01-26 [email protected] Roll Fuchsia Linux SDK from T4qTEa3T5CCSCIoJY... to akraNGn2lw4T1msgZ... (flutter/flutter#181509) 2026-01-26 [email protected] Roll Skia from be280d242a60 to f2c1aa140b79 (3 revisions) (flutter/flutter#181504) 2026-01-26 [email protected] Fixes metal vec3 uniform padding (flutter/flutter#181340) 2026-01-26 [email protected] Fixes duplicated import in accessibility test library (flutter/flutter#181506) 2026-01-26 [email protected] [Reland] Don't strip symbols from `libapp.so` on android by default (flutter/flutter#181275) 2026-01-26 [email protected] Fix Gradle path in Android Platform Embedder README. (flutter/flutter#181501) 2026-01-26 [email protected] Remove unused `ActivityLifecycleListener` class (flutter/flutter#181406) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…lutter#181275) Relands flutter#162464 Fixes flutter#170664 The only test that failed last time was `Linux_pixel_7pro android_obfuscate_test`, and I ran it locally (`flutter test test/integration.shard/android_obfuscate_test.dart `) to both repro the failure and verify it passes on this branch with the additional changes. Also does some stuff in the FGP: The reason we failed the tests last time was we were bundling of the libapp.so code into a jar in the aar case, instead of simply including it as its own file in the source sets. I let gemini go on that part, modifying it to no longer pack as a jar, but it looks correct to me. Now that the `libapp.so` file is simply included in this case, AGP is able to strip it (it's not hidden inside a jar). Because this changes the FGP build process for add to app, I manually verified that the add to app flow isn't broken for including a flutter module both as source and as an aar. <details> <summary>Before and after logs from the gradle task output</summary> Before: ``` > Task :flutter:stripReleaseDebugSymbols NO-SOURCE Skipping task ':flutter:stripReleaseDebugSymbols' as it has no source files and no previous output files. ``` After: ``` Task ':flutter:stripReleaseDebugSymbols' is not up-to-date because: No history is available. The input changes require a full rebuild for incremental task ':flutter:stripReleaseDebugSymbols'. C/C++: android.ndkVersion from module build.gradle is [28.2.13676358] C/C++: android.ndkVersion from module build.gradle is [28.2.13676358] C/C++: android.ndkPath from module build.gradle is not set C/C++: android.ndkPath from module build.gradle is not set C/C++: ndk.dir in local.properties is not set C/C++: ndk.dir in local.properties is not set C/C++: Not considering ANDROID_NDK_HOME because support was removed after deprecation period. C/C++: Not considering ANDROID_NDK_HOME because support was removed after deprecation period. C/C++: android.ndkVersion from module build.gradle is [28.2.13676358] C/C++: android.ndkPath from module build.gradle is not set C/C++: sdkFolder is /Users/mackall/Library/Android/sdk C/C++: ndk.dir in local.properties is not set C/C++: Not considering ANDROID_NDK_HOME because support was removed after deprecation period. C/C++: sdkFolder is /Users/mackall/Library/Android/sdk C/C++: sdkFolder is /Users/mackall/Library/Android/sdk Starting process 'command '/Users/mackall/Library/Android/sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip''. Working directory: /Users/mackall/development/BugTesting/mblahm/.android/Flutter Command: /Users/mackall/Library/Android/sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip --strip-unneeded -o /Users/mackall/development/BugTesting/mblahm/.android/Flutter/build/intermediates/stripped_native_libs/release/stripReleaseDebugSymbols/out/lib/armeabi-v7a/libapp.so /Users/mackall/development/BugTesting/mblahm/.android/Flutter/build/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib/armeabi-v7a/libapp.so Starting process 'command '/Users/mackall/Library/Android/sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip''. Working directory: /Users/mackall/development/BugTesting/mblahm/.android/Flutter Command: /Users/mackall/Library/Android/sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip --strip-unneeded -o /Users/mackall/development/BugTesting/mblahm/.android/Flutter/build/intermediates/stripped_native_libs/release/stripReleaseDebugSymbols/out/lib/x86_64/libapp.so /Users/mackall/development/BugTesting/mblahm/.android/Flutter/build/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib/x86_64/libapp.so Starting process 'command '/Users/mackall/Library/Android/sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip''. Working directory: /Users/mackall/development/BugTesting/mblahm/.android/Flutter Command: /Users/mackall/Library/Android/sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip --strip-unneeded -o /Users/mackall/development/BugTesting/mblahm/.android/Flutter/build/intermediates/stripped_native_libs/release/stripReleaseDebugSymbols/out/lib/arm64-v8a/libapp.so /Users/mackall/development/BugTesting/mblahm/.android/Flutter/build/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib/arm64-v8a/libapp.so Successfully started process 'command '/Users/mackall/Library/Android/sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip'' Successfully started process 'command '/Users/mackall/Library/Android/sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip'' Successfully started process 'command '/Users/mackall/Library/Android/sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip'' ``` </details> ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Gray Mackall <[email protected]>
Relands #162464
Fixes #170664
The only test that failed last time was
Linux_pixel_7pro android_obfuscate_test, and I ran it locally (flutter test test/integration.shard/android_obfuscate_test.dart) to both repro the failure and verify it passes on this branch with the additional changes.Also does some stuff in the FGP:
The reason we failed the tests last time was we were bundling of the libapp.so code into a jar in the aar case, instead of simply including it as its own file in the source sets. I let gemini go on that part, modifying it to no longer pack as a jar, but it looks correct to me. Now that the
libapp.sofile is simply included in this case, AGP is able to strip it (it's not hidden inside a jar).Because this changes the FGP build process for add to app, I manually verified that the add to app flow isn't broken for including a flutter module both as source and as an aar.
Before and after logs from the gradle task output
Before:
After:
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.