Skip to content

Add split-debug and obfuscation to build aar #56342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 8, 2020

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented May 5, 2020

Description

Add --split-debug-info and --obfuscate flags to build aar.

Related Issues

Fixes #56068
Obviates #56069

Tests

build_aar_test flag parsing. Confirmed the tests also passed on master when I commented out the --split-debug-info and --obfuscate parts, so nothing regressed.

Add build aar to android_obfuscate_test` devicelab test.

Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.

@jmagman jmagman added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. labels May 5, 2020
@jmagman jmagman requested review from xster and jonahwilliams May 5, 2020 02:25
@jmagman jmagman self-assigned this May 5, 2020
));
androidBuildInfo.add(
AndroidBuildInfo(
getBuildInfo(forcedBuildMode: BuildMode.fromName(buildMode)),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#56068 (comment)

The build_aar command would need to be refactored to get the buildInfo from the flutter command instead of manually constructing it.

Is this what you meant, @jonahwilliams?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! though there are some edges here. For example, If a user builds a debug aar with obfuscation enabled, the sources might be scrambled. This might cause confusion if there is some expectation that these flags only work on "release" builds

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xster What do you think the best user experience would be here?

  1. Ignore the flags for the debug and profile output
  2. Ignore the flags for the debug and profile output, and print a warning
  3. Only allow the flags accompanied by --no-debug and --no-profile

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW we do support --obfuscate on --debug flutter build apk --debug today, but not through flutter run. The former isn't very common so I didn't think it merited any interception, but it might be more common to build artifacts together here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for 2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ flutter build aar --target-platform=android-arm --obfuscate --split-debug-info=foo/                                  
Building flutter tool...
Changing current working directory to: /Users/magder/Projects/aaa
Dart obfuscation is not supported in Debug mode, skipping.              
Running Gradle task 'assembleAarDebug'...                               
Running Gradle task 'assembleAarDebug'... Done                     20.6s
✓ Built build/host/outputs/repo.
Dart obfuscation is not supported in Profile mode, skipping.            
Running Gradle task 'assembleAarProfile'...                             
Running Gradle task 'assembleAarProfile'... Done                   21.4s
✓ Built build/host/outputs/repo.
Running Gradle task 'assembleAarRelease'...                             
Running Gradle task 'assembleAarRelease'... Done                    3.2s
✓ Built build/host/outputs/repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG. "skipping" is a bit ambiguous since you didn't skip building debug/profile. Maybe just say building debug/release in unobfuscated mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to: "Dart obfuscation is not supported in Debug mode, building as unobfuscated."

});

tearDown(() {
tryToDelete(tempDir);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't ideal, but it's the pattern the rest of this file uses. I started yak shaving (hence #56335, #56331, #56330, #56329) but didn't get far enough to do #43863 or inject a fake process manager into the command (boy are commands are hard to test...)

Anyway it's no worse than it was...

@jmagman
Copy link
Member Author

jmagman commented May 5, 2020

Forgot to add the integration test.

expect(androidBuildInfo.targetArchs, <AndroidArch>[AndroidArch.armeabi_v7a, AndroidArch.arm64_v8a, AndroidArch.x86_64]);
}
expect(buildModes.length, 3);
expect(buildModes, contains(BuildMode.debug));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(androidBuildInfos.length, 3);

final List<BuildMode> buildModes = <BuildMode>[];
for (final AndroidBuildInfo androidBuildInfo in androidBuildInfos) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly overly pedantic, but It would be nice to separate the control flow from the expectations here. You could nest contains and predicate/isA<> matchers to accomplish this, though I don't know if its an improvement

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it, I think it's harder to read...

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nit

return TaskResult.failure('Found project name in obfuscated APK dart library');
}
if (foundAarProjectName) {
return TaskResult.failure('Found project name in obfuscated AAR dart library');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bleh this fails:

[android_obfuscate_test] [STDOUT] Executing: grep aaa jni/armeabi-v7a/libapp.so in /var/folders/mv/qlhc4vsj6tqct166rw3zwmth00mfq2/T/flutter_devicelab_gradle_plugin_test.bY7bhQ/aaa
[android_obfuscate_test] [STDOUT] stdout: Binary file jni/armeabi-v7a/libapp.so matches
...
Task result:
{
  "success": false,
  "reason": "Found project name in obfuscated AAR dart library"
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the build aar call into assemble in the same way?

@xster
Copy link
Member

xster commented May 5, 2020

LGTM. Thanks for fixing!

Comment on lines -569 to -571
if (androidBuildInfo.buildInfo.treeShakeIcons) {
command.add('-Pfont-subset=true');
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the wrong spot, I moved it out of the local engine check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnfield Can you confirm you didn't intentionally want the tree shake check to only happen with a local engine?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct - it should be able to work with both. I probably only tested with a local engine.

'-Poutput-dir=${buildDirectory.path}',
'-Pis-plugin=true',
'-PbuildNumber=1.0',
'-q',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the -q flag.

@fluttergithubbot fluttergithubbot merged commit 0a4f6cd into flutter:master May 8, 2020
@jmagman jmagman deleted the obfuscate-aar branch May 8, 2020 01:56
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add obfuscation option to flutter build aar also
6 participants