Repository navigation
Decide on a path to stop stripping libapp.so and libflutter.so by default for android builds #155576
Description
Context #60240.
We currently strip debug symbols when building the the AOT snapshot and when building the engine. This means that when Flutter developers build an appbundle (flutter build appbundle) these debug symbols are not available to the Android Gradle plugin (AGP), and therefore they obviously can't be included in the appbundle, which results in the warning in the play store that we see in the linked issue.
Since AGP 4.1, AGP itself can handle both stripping the debug symbols from the native code, and automatically including it in the appbundle in a way that is available to app stores, but does not get delivered to end users* (see https://support.google.com/googleplay/android-developer/answer/9848633#upload_file). So ideally, we could simply stop stripping these files when building for Android, and instead let AGP handle the debug symbols.
HOWEVER - the Flutter Gradle plugin has for some time now vended a recommended version of the NDK (flutter.ndkVersion) that we use to specify the ndkVersion property in apps gradle files, and importantly, if an app specifies an ndk version, and doesn't have that ndk version installed locally, the app will build but silently fail to strip the debug symbols, meaning that they end up in the final app (greatly inflating the app size).
So before we can stop stripping the debug symbols from these files by default, we need to decide on a path that ensures we don't create a foot gun where developers build, unaware that they don't have the ndk version they are specifying installed, and end up with unnecessarily large apps.
In my mind there are two main options, but other suggestions are welcome:
- Get rid of
flutter.ndkVersionentirely via a migrator. If users don't specify an ndk version, apps will instead use the default version provided by AGP. This is option two in this section of the android docs - AGP will download the version by default. There is also a community issue suggesting we do this. - Keep
flutter.ndkVersionaround, and instead modify the flutter tool/flutter doctor to ensure that we check/enforce that users have the version of the ndk that we specify installed.
* More specifically, the symbols get stripped and included in a BUNDLE-METADATA subdirectory of the app bundle format, see this comment for more details.
Activity
AbdeMohlbi commentedon Sep 23, 2024
What does happen when some used plugins have a newer version then flutter.ndkversion inside gradle files ? Does the build fail in this case? No conflicts?
gmackall commentedon Oct 3, 2024
Potentially, for 1, write a migrator that instead of removing the line, replaces
flutter.ndkVersionwith AGPs variable that holds their preferred ndk version, if such a variable existsSameri11 commentedon Oct 6, 2024
I personally don't really like first option because, in my opinion, there should be 1 source of truth for things like that. At least because there are already warnings in android builds, alarming about different versions of NDK in plugins and app (example). Although I do not think that this warning is fixable only by specifying NDK version (it doesn't work already lol), I think that relying on standard AGP mechanism for NDK downloading is another step back from avoiding this kind of problems.
Plus, I believe that another teams on a path of solving similar problem, for example #144530
I think it would be create doctor validator and, to enforce, Gradle's warning for debug/profile and error for release builds respectfully, if there's no needed ndk version found.
gmackall commentedon Oct 22, 2024
Still no decision has been made, but adding some more info that according to my local testing and some internal info, apparently AGP will automatically download the NDK for every use case except for when it is needed for stripping debug symbols from prebuilt libraries.
So we can't rely on AGP to guarantee the availability of the NDK.
AbdeMohlbi commentedon Oct 23, 2024
If i recall correctly it's not that hard to know the ndk versions installed on a machine , the problem is it compatible ?
for instance if u opened a fresh project and add sharedPrefernces or some other package when running the app it will prompt that this project require newer ndk version for exemple 27 and flutter.ndkVersion is 26 , so some users may find it kinda deceiving if flutter doctor would list that ndk is installed
Force automatic ndk download when building for Android (#159756)
Reverts "Force automatic ndk download when building for Android (#159756
github-actions commentedon Dec 27, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.