-
Notifications
You must be signed in to change notification settings - Fork 28.7k
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
Conversation
)); | ||
androidBuildInfo.add( | ||
AndroidBuildInfo( | ||
getBuildInfo(forcedBuildMode: BuildMode.fromName(buildMode)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
- Ignore the flags for the debug and profile output
- Ignore the flags for the debug and profile output, and print a warning
- Only allow the flags accompanied by
--no-debug
and--no-profile
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote for 2
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
There was a problem hiding this 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'); |
There was a problem hiding this comment.
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"
}
There was a problem hiding this comment.
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?
LGTM. Thanks for fixing! |
if (androidBuildInfo.buildInfo.treeShakeIcons) { | ||
command.add('-Pfont-subset=true'); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the -q
flag.
Description
Add
--split-debug-info
and--obfuscate
flags tobuild 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
///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change