Skip to content

Commit 6b57cc2

Browse files
[Xamarin.Android.Build.Tasks] redistribute proguard-android.txt from 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
1 parent 4559426 commit 6b57cc2

File tree

10 files changed

+83
-3
lines changed

10 files changed

+83
-3
lines changed

THIRD-PARTY-NOTICES.TXT

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ bring it to our attention. Post an issue or email us:
1111

1212
The attached notices are provided for information only.
1313

14-
1. android/platform/tools/base (https://android.googlesource.com/platform/tools/base/+/d41d662dbf89f9b60ca6256415a059c0107749b8/sdk-common/NOTICE)
14+
1. android/platform/tools/base (https://android.googlesource.com/platform/tools/base/+/refs/heads/main/sdk-common/NOTICE)
1515
2. bazelbuild/bazel (https://github.com/bazelbuild/bazel/)
1616
3. chys87/constexpr-xxh3 (https://github.com/chys87/constexpr-xxh3/)
1717
4. Cyan4973/xxHash (https://github.com/Cyan4973/xxHash/)

Xamarin.Android.sln

+7
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FFCF518F-2A4
123123
EndProject
124124
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Android.Sdk.Analysis", "src\Microsoft.Android.Sdk.Analysis\Microsoft.Android.Sdk.Analysis.csproj", "{5E806C9F-1B67-4B6B-A6AB-258834250DBB}"
125125
EndProject
126+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "proguard-android", "src\proguard-android\proguard-android.csproj", "{5FD0133B-69E5-4474-9B67-9FD1D0150C70}"
127+
EndProject
126128
Global
127129
GlobalSection(SolutionConfigurationPlatforms) = preSolution
128130
Debug|AnyCPU = Debug|AnyCPU
@@ -341,6 +343,10 @@ Global
341343
{5E806C9F-1B67-4B6B-A6AB-258834250DBB}.Debug|AnyCPU.Build.0 = Debug|Any CPU
342344
{5E806C9F-1B67-4B6B-A6AB-258834250DBB}.Release|AnyCPU.ActiveCfg = Release|Any CPU
343345
{5E806C9F-1B67-4B6B-A6AB-258834250DBB}.Release|AnyCPU.Build.0 = Release|Any CPU
346+
{5FD0133B-69E5-4474-9B67-9FD1D0150C70}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
347+
{5FD0133B-69E5-4474-9B67-9FD1D0150C70}.Debug|AnyCPU.Build.0 = Debug|Any CPU
348+
{5FD0133B-69E5-4474-9B67-9FD1D0150C70}.Release|AnyCPU.ActiveCfg = Release|Any CPU
349+
{5FD0133B-69E5-4474-9B67-9FD1D0150C70}.Release|AnyCPU.Build.0 = Release|Any CPU
344350
EndGlobalSection
345351
GlobalSection(SolutionProperties) = preSolution
346352
HideSolutionNode = FALSE
@@ -399,6 +405,7 @@ Global
399405
{BA4D889D-066B-4C2C-A973-09E319CBC396} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62}
400406
{A39B6D7C-6616-40D6-8AE4-C6CEE93D2708} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
401407
{5E806C9F-1B67-4B6B-A6AB-258834250DBB} = {FFCF518F-2A4A-40A2-9174-2EE13B76C723}
408+
{5FD0133B-69E5-4474-9B67-9FD1D0150C70} = {FFCF518F-2A4A-40A2-9174-2EE13B76C723}
402409
EndGlobalSection
403410
GlobalSection(ExtensibilityGlobals) = postSolution
404411
SolutionGuid = {53A1F287-EFB2-4D97-A4BB-4A5E145613F6}

build-tools/installers/create-installers.targets

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)java_runtime_net6.dex" ExcludeFromLegacy="true" />
139139
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)java_runtime_fastdev_net6.dex" ExcludeFromLegacy="true" />
140140
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)manifestmerger.jar" />
141+
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)proguard-android.txt" />
141142
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)protobuf-net.dll" />
142143
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)System.CodeDom.dll" />
143144
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)System.Collections.Immutable.dll" />

build-tools/xaprepare/xaprepare/ThirdPartyNotices/Xamarin.Android.Build.Tasks.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Xamarin.Android.Prepare
77
[TPN]
88
class XamarinAndroidBuildTasks_AOSP : ThirdPartyNotice
99
{
10-
static readonly Uri url = new Uri ("https://android.googlesource.com/platform/tools/base/+/d41d662dbf89f9b60ca6256415a059c0107749b8/sdk-common/NOTICE");
10+
static readonly Uri url = new Uri ("https://android.googlesource.com/platform/tools/base/+/refs/heads/main/sdk-common/NOTICE");
1111

1212
public override string LicenseText => String.Empty;
1313
public override string LicenseFile => CommonLicenses.Apache20Path;

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,7 @@ because xbuild doesn't support framework reference assemblies.
18991899
<_ProguardConfiguration Include="$(ProguardConfigFiles)" />
19001900
</ItemGroup>
19011901
<ItemGroup Condition=" '$(ProguardConfigFiles)' == '' ">
1902-
<_ProguardConfiguration Include="$(_AndroidSdkDirectory)tools\proguard\proguard-android.txt" Condition=" Exists ('$(_AndroidSdkDirectory)tools\proguard\proguard-android.txt') " />
1902+
<_ProguardConfiguration Include="$(MSBuildThisFileDirectory)proguard-android.txt" />
19031903
<_ProguardConfiguration Include="$(IntermediateOutputPath)proguard\proguard_xamarin.cfg" Condition=" '$(AndroidLinkTool)' != '' " />
19041904
<_ProguardConfiguration Include="$(_ProguardProjectConfiguration)" Condition=" '$(AndroidLinkTool)' != '' " />
19051905
<_ProguardConfiguration Include="$(IntermediateOutputPath)proguard\proguard_project_primary.cfg" Condition=" '$(AndroidLinkTool)' != '' " />

src/proguard-android/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea/
2+
build/
3+
out/
4+
.classpath
5+
.project
6+
.settings/

src/proguard-android/build.gradle

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id 'com.android.application' version '8.7.0'
3+
}
4+
5+
repositories {
6+
google()
7+
mavenCentral()
8+
}
9+
10+
android {
11+
namespace 'com.microsoft.proguard.android'
12+
// Setting the minimum we support at the moment, might not matter
13+
compileSdk 21
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.Build.NoTargets">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
6+
<OutputPath Condition="'$(OutputPath)'==''">bin\$(Configuration)</OutputPath>
7+
</PropertyGroup>
8+
<Import Project="..\..\Configuration.props" />
9+
<Import Project="proguard-android.targets" />
10+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<_Destination>$(MicrosoftAndroidSdkOutDir)proguard-android.txt</_Destination>
4+
</PropertyGroup>
5+
6+
<Target Name="_GenerateProGuardRules"
7+
BeforeTargets="Build"
8+
Inputs="$(MSBuildThisFile);build.gradle;settings.gradle"
9+
Outputs="$(_Destination)">
10+
<Exec
11+
Command="&quot;$(GradleWPath)&quot; extractProguardFiles $(GradleArgs)"
12+
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);APP_HOME=$(GradleHome)"
13+
WorkingDirectory="$(MSBuildThisFileDirectory)"
14+
/>
15+
<ItemGroup>
16+
<_ProguardRules Include="$(MSBuildThisFileDirectory)build\intermediates\default_proguard_files\global\proguard-android.txt-*" />
17+
</ItemGroup>
18+
<Copy
19+
SourceFiles="@(_ProguardRules)"
20+
DestinationFiles="$(_Destination)"
21+
/>
22+
<Touch Files="$(_Destination)" />
23+
</Target>
24+
25+
<Target Name="_CleanProguardRules" BeforeTargets="Clean">
26+
<Delete Files="$(_Destination)" />
27+
<Exec
28+
Command="&quot;$(GradleWPath)&quot; clean $(GradleArgs)"
29+
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);APP_HOME=$(GradleHome)"
30+
WorkingDirectory="$(MSBuildThisFileDirectory)"
31+
/>
32+
</Target>
33+
34+
</Project>

src/proguard-android/settings.gradle

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pluginManagement {
2+
repositories {
3+
gradlePluginPortal()
4+
google()
5+
mavenCentral()
6+
}
7+
}
8+
rootProject.name = 'proguard-android'

0 commit comments

Comments
 (0)