-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] redistribute
proguard-android.txt
fro…
…m Android gradle plugin (#9485) Context: https://discord.com/channels/732297728826277939/732297837953679412/1303383272918618163 A customer found their app grew in size when building on Windows versus macOS. The difference being a file that was passed to the `<R8/>` task on Windows, but not on macOS: C:\Users\[username]\AppData\Local\Android\Sdk\tools\proguard\proguard-android.txt `tools` is *ancient*, as any Android SDK should be using `cmdline-tools` now. Let's stop using this file as a default set of proguard rules. But we need to use the *right* set of proguard rules, reading the text of the old one: > This file is no longer maintained and is not used by new (2.2+) > versions of the # Android plugin for Gradle. Instead, the Android > plugin for Gradle generates the # default rules at build time and > stores them in the build directory. I found the source code for the gradle task that generates the new files at: * https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:build-system/gradle-core/src/main/java/com/android/build/gradle/ProguardFiles.java;l=116 In order to get this file, we can setup an empty gradle project using the Android gradle plugin: plugins { id 'com.android.application' version '8.7.0' } Which, hopefully, dependabot is able to update this version. Then we can run the task: .\gradlew extractProguardFiles This outputs files such as: src\proguard-android\build\intermediates\default_proguard_files\global\proguard-android-optimize.txt-8.7.0 src\proguard-android\build\intermediates\default_proguard_files\global\proguard-android.txt-8.7.0 src\proguard-android\build\intermediates\default_proguard_files\global\proguard-defaults.txt-8.7.0 For now, I simply redistributed the `proguard-android.txt` file, but we could consider making `proguard-android-optimize.txt` useable in the future. I believe the only difference is the `-allowaccessmodification` flag, which users could put in their own proguard rules. Also, updated TPN url for: https://android.googlesource.com/platform/tools/base/+/refs/heads/main/sdk-common/NOTICE
- Loading branch information
1 parent
4559426
commit 6b57cc2
Showing
10 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.idea/ | ||
build/ | ||
out/ | ||
.classpath | ||
.project | ||
.settings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
plugins { | ||
id 'com.android.application' version '8.7.0' | ||
} | ||
|
||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
|
||
android { | ||
namespace 'com.microsoft.proguard.android' | ||
// Setting the minimum we support at the moment, might not matter | ||
compileSdk 21 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.Build.NoTargets"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'==''">bin\$(Configuration)</OutputPath> | ||
</PropertyGroup> | ||
<Import Project="..\..\Configuration.props" /> | ||
<Import Project="proguard-android.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<_Destination>$(MicrosoftAndroidSdkOutDir)proguard-android.txt</_Destination> | ||
</PropertyGroup> | ||
|
||
<Target Name="_GenerateProGuardRules" | ||
BeforeTargets="Build" | ||
Inputs="$(MSBuildThisFile);build.gradle;settings.gradle" | ||
Outputs="$(_Destination)"> | ||
<Exec | ||
Command=""$(GradleWPath)" extractProguardFiles $(GradleArgs)" | ||
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);APP_HOME=$(GradleHome)" | ||
WorkingDirectory="$(MSBuildThisFileDirectory)" | ||
/> | ||
<ItemGroup> | ||
<_ProguardRules Include="$(MSBuildThisFileDirectory)build\intermediates\default_proguard_files\global\proguard-android.txt-*" /> | ||
</ItemGroup> | ||
<Copy | ||
SourceFiles="@(_ProguardRules)" | ||
DestinationFiles="$(_Destination)" | ||
/> | ||
<Touch Files="$(_Destination)" /> | ||
</Target> | ||
|
||
<Target Name="_CleanProguardRules" BeforeTargets="Clean"> | ||
<Delete Files="$(_Destination)" /> | ||
<Exec | ||
Command=""$(GradleWPath)" clean $(GradleArgs)" | ||
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);APP_HOME=$(GradleHome)" | ||
WorkingDirectory="$(MSBuildThisFileDirectory)" | ||
/> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pluginManagement { | ||
repositories { | ||
gradlePluginPortal() | ||
google() | ||
mavenCentral() | ||
} | ||
} | ||
rootProject.name = 'proguard-android' |