Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cb9d6c7
remake engine pr changing default for symbol stripping on android
Jan 13, 2025
83a2a40
Merge branch 'master' into remake_dont_strip_android_symbols
gmackall Jan 27, 2025
8dfb472
Merge branch 'flutter:master' into remake_dont_strip_android_symbols
gmackall Jan 27, 2025
49fc677
Merge branch 'flutter:master' into remake_dont_strip_android_symbols
gmackall Jan 28, 2025
8adad84
start for enforcing app bundles have debug symbols included
Jan 29, 2025
0be2826
enforce check, format
Jan 29, 2025
d6e1f1e
only verify this for aab
Jan 29, 2025
4cdf4cf
Merge branch 'master' into remake_dont_strip_android_symbols
gmackall Jan 29, 2025
74877d6
push missed name change
Jan 29, 2025
6350337
apply to each architecture, and make only for release
Jan 29, 2025
7ab7370
format
Jan 29, 2025
d0d975f
only test for at least one arch, instead of all
Jan 29, 2025
17f0772
its apkanalyzer.bat on windows
Jan 29, 2025
f46259e
add tests
Jan 30, 2025
6e5fcff
fix test name
Jan 30, 2025
1b9913f
test to ensure we don't invoke apkanalyzer in debug
Jan 30, 2025
3b1b7b9
make the test not hardcoded
Jan 30, 2025
4cae103
format
Jan 30, 2025
f5ee7bc
Merge branch 'master' into remake_dont_strip_android_symbols
gmackall Jan 30, 2025
0a3ab63
pull out common portions of test gradle command, and use a group
Jan 30, 2025
7b1201b
pull apkanalyzer output to top group level
Jan 30, 2025
448da11
doc on where apkanalyzer output comes from
Jan 30, 2025
e9b728b
add verbose logs, and change to just checkign for libflutter.so.sym
Jan 30, 2025
6d029a6
the stdout too
Jan 30, 2025
becde4a
make helpers for test at group level
Jan 30, 2025
2a25bf4
remove extra pointless calls to create aabfile
Jan 30, 2025
dc0090f
dont assign aabfile in the one test we don't use the value (still mak…
Jan 30, 2025
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
8 changes: 6 additions & 2 deletions engine/src/flutter/tools/gn
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,12 @@ def to_gn_args(args):
if args.build_embedder_examples is not None:
gn_args['build_embedder_examples'] = args.build_embedder_examples

gn_args['stripped_symbols'] = args.stripped
if args.stripped is True:
gn_args['stripped_symbols'] = True
elif args.stripped is False:
gn_args['stripped_symbols'] = False
else:
gn_args['stripped_symbols'] = args.target_os != 'android'

if args.msan:
gn_args['is_msan'] = True
Expand Down Expand Up @@ -1113,7 +1118,6 @@ def parse_args(args):

parser.add_argument(
'--stripped',
default=True,
action='store_true',
help='Strip debug symbols from the output. This defaults to true and has no effect on iOS.'
)
Expand Down
76 changes: 76 additions & 0 deletions packages/flutter_tools/lib/src/android/gradle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ import 'migrations/top_level_gradle_build_file_migration.dart';
final RegExp _kBuildVariantRegex = RegExp('^BuildVariant: (?<$_kBuildVariantRegexGroupName>.*)\$');
const String _kBuildVariantRegexGroupName = 'variant';
const String _kBuildVariantTaskName = 'printBuildVariants';
@visibleForTesting
const String failedToStripDebugSymbolsErrorMessage = r'''
Release app bundle failed to strip debug symbols from native libraries. Please run flutter doctor and ensure that the Android toolchain does not report any issues.

Otherwise, file an issue at https://github.com/flutter/flutter/issues.''';

typedef _OutputParser = void Function(String line);

Expand Down Expand Up @@ -86,6 +91,9 @@ Directory getBundleDirectory(FlutterProject project) {
.childDirectory('bundle');
}

@visibleForTesting
final String apkAnalyzerBinaryName = globals.platform.isWindows ? 'apkanalyzer.bat' : 'apkanalyzer';

/// The directory where the repo is generated.
/// Only applicable to AARs.
Directory getRepoDirectory(Directory buildDirectory) {
Expand Down Expand Up @@ -577,6 +585,16 @@ class AndroidGradleBuilder implements AndroidBuilder {

if (isBuildingBundle) {
final File bundleFile = findBundleFile(project, buildInfo, _logger, _analytics);

if ((buildInfo.mode == BuildMode.release) &&
!(await _isAabStrippedOfDebugSymbols(
project,
bundleFile.path,
androidBuildInfo.targetArchs,
))) {
throwToolExit(failedToStripDebugSymbolsErrorMessage);
}

final String appSize =
(buildInfo.mode == BuildMode.debug)
? '' // Don't display the size when building a debug variant.
Expand Down Expand Up @@ -632,6 +650,64 @@ class AndroidGradleBuilder implements AndroidBuilder {
}
}

// Checks whether AGP has successfully stripped debug symbols from native libraries
// - libflutter.so, aka the engine
// - lib_app.so, aka the framework dart code
// and moved them to the BUNDLE-METADATA directory. Block the build if this
// isn't successful, as it means that debug symbols are getting included in
// the final app that would be delivered to users.
Future<bool> _isAabStrippedOfDebugSymbols(
FlutterProject project,
String aabPath,
Iterable<AndroidArch> targetArchs,
) async {
if (globals.androidSdk == null) {
_logger.printTrace(
'Failed to find android sdk when checking final appbundle for debug symbols.',
);
return false;
}
if (!globals.androidSdk!.cmdlineToolsAvailable) {
_logger.printTrace(
'Failed to find cmdline-tools when checking final appbundle for debug symbols.',
);
return false;
}
final String? apkAnalyzerPath = globals.androidSdk!.getCmdlineToolsPath(apkAnalyzerBinaryName);
if (apkAnalyzerPath == null) {
_logger.printTrace(
'Failed to find apkanalyzer when checking final appbundle for debug symbols.',
);
return false;
}

final RunResult result = await _processUtils.run(
<String>[apkAnalyzerPath, 'files', 'list', aabPath],
workingDirectory: project.android.hostAppGradleRoot.path,
environment: _java?.environment,
);

if (result.exitCode != 0) {
_logger.printTrace(
'apkanalyzer finished with exit code 0 when checking final appbundle for debug symbols.\n'
'stderr was: ${result.stderr}\n'
'and stdout was: ${result.stdout}',
);
return false;
}

// As long as libflutter.so.sym is present for at least one architecture,
// assume AGP succeeded in stripping.
if (result.stdout.contains('libflutter.so.sym')) {
return true;
}

_logger.printTrace(
'libflutter.so.sym not present when checking final appbundle for debug symbols.',
);
return false;
}

Future<void> _performCodeSizeAnalysis(
String kind,
File zipFile,
Expand Down
Loading