-
Notifications
You must be signed in to change notification settings - Fork 538
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
Aapt and Aapt2 MSBuild tasks do not yet use -G and --proguard options to help generate rules when ProGuard or R8 is enabled #3636
Comments
I'd be happy to take a try setting up a PR to add these options to the |
I wonder if the Xamarin team could place a higher priority on this bug. Xamarin app are already really large in terms of App Store size and essentially this means Proguard can't be used at all. With upcoming app store changes around the use of bundles etc all this sort of stuff is going to be critical. |
I should probably add a few words to my previous comment for clarity. Instead of "anyone else," I should have said "anyone else on the team." I suspect someone else on the team might beat me to adding this functionality. |
…ules Context: https://developer.android.com/studio/build/shrink-code#configuration-files Fixes: http://work.azdo.io/825420 Fixes: dotnet#3636 Let's say you used the following code fragment in an Android layout: <android.support.v7.widget.Toolbar /> Currently, you would need to add a ProGuard rule regardless if you were using ProGuard or R8. Fortunately, `aapt2` has a command-line switch: > aapt2 link -h ... --proguard arg Output file for generated Proguard rules. According to the Google docs for R8: AAPT2 generates keep rules based on references to classes in your app’s manifest, layouts, and other app resources. For example, AAPT2 includes a keep rule for each Activity that you register in your app’s manifest as an entry point. I added a new `ProguardRuleOutput` property for `<Aapt2Link/>` and set it in cases where `$(AndroidLinkTool)` is not blank. I added this file to `@(ProguardConfiguration)`, so it will get picked up by ProGuard or R8. I updated an existing test for this scenario, checking that a type is generated in the rules and exists in the final `classes.dex` file.
…ules Context: https://developer.android.com/studio/build/shrink-code#configuration-files Fixes: http://work.azdo.io/825420 Fixes: dotnet#3636 Let's say you used the following code fragment in an Android layout: <android.support.v7.widget.Toolbar /> Currently, you would need to add a ProGuard rule regardless if you were using ProGuard or R8. Fortunately, `aapt2` has a command-line switch: > aapt2 link -h ... --proguard arg Output file for generated Proguard rules. According to the Google docs for R8: AAPT2 generates keep rules based on references to classes in your app’s manifest, layouts, and other app resources. For example, AAPT2 includes a keep rule for each Activity that you register in your app’s manifest as an entry point. I added a new `ProguardRuleOutput` property for `<Aapt2Link/>` and set it in cases where `$(AndroidLinkTool)` is not blank. I added this file to `@(ProguardConfiguration)`, so it will get picked up by ProGuard or R8. I updated an existing test for this scenario, checking that a type is generated in the rules and exists in the final `classes.dex` file.
…ules (#3899) Context: https://developer.android.com/studio/build/shrink-code#configuration-files Fixes: http://work.azdo.io/825420 Fixes: #3636 Let's say you used the following code fragment in an Android layout: <android.support.v7.widget.Toolbar /> Currently, you would need to add a ProGuard rule regardless if you were using ProGuard or R8. Fortunately, `aapt2` has a command-line switch: > aapt2 link -h ... --proguard arg Output file for generated Proguard rules. According to the Google docs for R8: AAPT2 generates keep rules based on references to classes in your app’s manifest, layouts, and other app resources. For example, AAPT2 includes a keep rule for each Activity that you register in your app’s manifest as an entry point. I added a new `ProguardRuleOutput` property for `<Aapt2Link/>` and set it in cases where `$(AndroidLinkTool)` is not blank. I added this file to `@(ProguardConfiguration)`, so it will get picked up by ProGuard or R8. I updated an existing test for this scenario, checking that a type is generated in the rules and exists in the final `classes.dex` file.
Release status update A new Preview version has now been published on Windows that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix. The fix is not yet available on macOS. I will update this item again when a Preview version with the fix is available on macOS. Fix included in Xamarin.Android 10.2.100.7 Fix included on Windows in Visual Studio 2019 version 16.6 Preview 1. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview. Fix not yet available on macOS. |
Release status update A new Preview version has now been published on macOS that includes the fix for this item. The fix is not yet included in a Release version. I will update this again when a Release version is available that includes the fix. Fix included in Xamarin.Android 10.3.0.33. Fix included on macOS in Visual Studio 2019 for Mac version 8.6 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel. (Fix also included on Windows in Visual Studio 2019 version 16.6 Preview 1 and higher. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.) |
Release status update A new Release version has now been published that includes the fix for this item. Fix included in Xamarin.Android 10.3.1.0. Fix included on Windows in Visual Studio 2019 version 16.6. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/. Fix included on macOS in Visual Studio 2019 for Mac version 8.6. To get the new version that includes the fix, check for the latest updates on the Stable updater channel. |
Previous related reports:
Steps to reproduce
Example project: SingleViewAndroidApp1.zip
Expected behaviors
In a Gradle build in Android Studio for a matching project, some important types are preserved by app\build\intermediates\proguard-rules\release\aapt_rules.txt. Based on those results, I believe the expected behaviors are:
The
Aapt2
task passes the--proguard aapt_rules.txt
option toaapt2.exe
and then passes the resulting aapt_rules.txt file to ProGuard or R8.(Or for
aapt
, theAapt
task passes the-G aapt_rules.txt
option toaapt.exe
and then passes the resulting aapt_rules.txt file to ProGuard or R8.)The app runs without error.
Actual behaviors
The
Aapt2
task does not pass the--proguard
option toaapt2.exe
, and theAapt
task does not pass the-G
option toaapt.exe
.The app exits during startup because some required types are missing:
Manual workaround, proof of concept
If the project has Use incremental Android packaging system (aapt2) enabled, add the following lines to the .csproj file:
Or if the project does not have the incremental Android packaging system enabled, add the following lines instead:
Build and run the app again to generate the aapt_rules.txt file in the project directory.
Add the new aapt_rules.txt file to project in the Solution Explorer, and set the Build Action to ProguardConfiguration.
Remove the lines from the .csproj that were added in step 1 (to keep the generated aapt_fules.txt under careful manual control for this proof of concept).
Clean, rebuild, and rerun the app.
The app now launches successfully.
Version information
This behavior exists in Visual Studio 2019 version 16.4 Int Preview with Xamarin.Android 10.0.0.40.
This behavior has been the same for the built-in template projects since back to at least Visual Studio 2019 version 16.1 with Xamarin.Android 9.3.0.23.
The text was updated successfully, but these errors were encountered: