Skip to content

R8 linking causes runtime crashes on new IDE installations due to missing proguard rules file #8397

@tipa

Description

@tipa

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

VS 2022 17.7.4

Description

I am using R8 linking in Release mode as it produces much smaller APK files:

  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <AndroidLinkTool>r8</AndroidLinkTool>
    <TrimMode>full</TrimMode>
  </PropertyGroup>

On fresh installations of Visual Studio + the Android SDK, the tools/proguard/ folder is missing, causing runtime crashes, because too much is being linked out (e.g. android.view.View_IOnClickListenerImplementor)

Even if it is opt-in, I would expect the R8 linking to work, as it is also documented here: https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/D8andR8.md

Steps to Reproduce

  1. Freshly install VS 2022 incl. Android SDK (alternatively, delete existing C:\Program Files (x86)\Android\android-sdk\tools\proguard folder)
  2. Enable R8 using AndroidLinkTool property
  3. Build & run the app in Release mode

Did you find any workaround?

It is possible to workaround the problem by copying one of those files into the C:\Program Files (x86)\Android\android-sdk\tools\proguard folder and rename it to proguard-android.txt:
https://android.googlesource.com/platform/sdk/+/refs/heads/main/files/proguard-android.txt
https://android.googlesource.com/platform/sdk/+/refs/heads/main/files/proguard-android-optimize.txt

However, this workaround only seems to work when building with .NET7 - when using .NET8, the app crashes regardless

Relevant log output

C:\Program Files (x86)\Android\android-sdk\tools\proguard\proguard-android.txt : warning XA4304: ProGuard configuration file 'C:\Program Files (x86)\Android\an
droid-sdk\tools\proguard\proguard-android.txt' was not found. 

Possibly related bug report: #3789

Metadata

Metadata

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions