dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 527 forks source link

Review our current behavior for default proguard rules (r8 & proguard) #3789

Open jonathanpeppers opened 5 years ago

jonathanpeppers commented 5 years ago

The Problem

Context: https://github.com/xamarin/xamarin-android/pull/3787#discussion_r334958805

We use these proguard rules from the Android SDK:

C:\Program Files (x86)\Android\android-sdk\tools\proguard\proguard-android.txt

Two questions/issues:

  1. Can the user's proguard rules override these?
  2. Should we even be using this file anymore?

The header says:

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
#
# 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.

Expected Behavior

We should try to match the behavior of the Android Gradle Plugin & Android Studio. User's proguard rules should be able to override what is set by default.

Actual Behavior

Not sure what it is doing currently? Looks like the behavior would be the same for both ProGuard & R8.

brendanzagaeski commented 5 years ago

For the behavior mentioned in the proguard-android.txt header:

Instead, the Android plugin for Gradle generates the default rules at build time and stores them in the build directory.

I suspect that might match the behavior mentioned in https://github.com/xamarin/xamarin-android/issues/3636 about passing the -G and --proguard options to AAPT and AAPT2, so I suspect we might want to resolve that issue https://github.com/xamarin/xamarin-android/issues/3636 too as part of resolving this issue https://github.com/xamarin/xamarin-android/issues/3789.

tipa commented 1 year ago

Has there been any updates to this? I have stumbled over this issue after Xamarin wasn't able to find the ProGuard file any more ("ProGuard configuration file [...] was not found"). I have also found that Google seems to recommend using the proguard-android-optimize.txt file in their docs: https://developer.android.com/studio/build/shrink-code#enable - but maybe these additional "optimizations" could cause problems with Xamarin? This file still seems to be generated at compile time and not be the same version in the SDK folder