Xamarin-android: R8 throws an error when code shrinker is set to none

Created on 18 Mar 2020  路  14Comments  路  Source: xamarin/xamarin-android

Steps to Reproduce

  1. Create empty project
  2. Install package com.onesginal,
  3. Set DexCompiler to d8
  4. Set Code Shrinker to none
  5. Enable multidex

    Expected Behavior

There are no errors from R8 (because code shrinker is set to none)

Actual Behavior

R8 Fires error

2>R8 : warning : Missing class: com.google.android.gms.location.LocationListener
2>R8 : error : Compilation can't be completed because some library classes are missing.

When mulitdex is disabled, compilation goes without error.

Version Information

All details, sample repo, and more information are here: https://github.com/OneSignal/OneSignal-Xamarin-SDK/issues/185

Why R8 is fired when mulidex is enabled? If that is default behavior, then visual studio csproj editor should check "codeshrinker" to d8 automatically when selecting multidex, otherwise developer don't know whats happening.

App+Library Build

Most helpful comment

And what do you think about explicit setting r8 if multi-dex is enabled?

These are two different things. One is generating classes.dex, classes2.dex, etc., and the other is stripping unused Java code.

They invoke different command-line arguments, you can see how it works here:

https://github.com/xamarin/xamarin-android/blob/32df0048abd271e4246608f9458a7af1cf55893c/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs#L55-L131

I agree it's confusing both these settings run r8...

All 14 comments

Same issue facing R8 error in any mode (debug or release) even if code shrinker is set to none.
tried fixing this R8 issues with -dontwarn tag in proguard.cfg , cleaning sloution and deleting obj and bin folders and when ran application with debug mode throws error on app start up at MainActivity at base.OnCreate(bundle);

Same solution Working well on 16.4 after updating to 16.5 facing this issue.

** Please provide workaround as i am stuck, i cannot run my applications.

For now, my workaround is disabling R8/D8 in favor DX and proguard.

@jonathanpeppers I remember you worked on something like this in the past is that correct?

Why R8 is fired when mulidex is enabled? If that is default behavior, then visual studio csproj editor should check "codeshrinker" to d8 automatically when selecting multidex, otherwise developer don't know whats happening.

We have to run r8 for multi-dex support. This will not be using the code shrinking functionality unless you have AndroidLinkTool=r8.

Unfortunately r8 complains with an error like this if it can't find all java types used by the app:

2>R8 : warning : Missing class: com.google.android.gms.location.LocationListener
2>R8 : error : Compilation can't be completed because some library classes are missing.

I suspect that a missing NuGet package could solve the problem. I'll try the sample, I am not hitting an error with an empty project.

@PawKanarek I installed Xamarin.GooglePlayServices.Location and the problem went away.

Does OneSignal need to add that as a dependency for their NuGet package?

@jonathanpeppers Thanks! As i said, error is only with com.onesignal nuget package installed. You don't need to try sample as i opened new issue for the OneSignal team. All my concerns for the Xamarin.Android were about R8 error messages when i explicit said i don't want it.

We have to run r8 for multi-dex support

So maybe there should be option that automatically sets r8, when multidex is enabled? I've lost whole day to figure out whats going on, and why im getting errors abour r8 when option was disabled. If r8 is necessary part of muli-dex, then that info should be explicitly announced.

I _suspect_ that if r8 is giving an error like this, OneSignal is actually missing some Java classes its using from Google Play Services.

I bet you get a crash at runtime if you use the right API from their SDK.

I installed Xamarin.GooglePlayServices.Location and the problem went away.

@jonathanpeppers You made my day! My project now runs on d8 and multi-dex. Thanks!

And what do you think about explicit setting r8 if multi-dex is enabled?

And what do you think about explicit setting r8 if multi-dex is enabled?

These are two different things. One is generating classes.dex, classes2.dex, etc., and the other is stripping unused Java code.

They invoke different command-line arguments, you can see how it works here:

https://github.com/xamarin/xamarin-android/blob/32df0048abd271e4246608f9458a7af1cf55893c/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs#L55-L131

I agree it's confusing both these settings run r8...

@PawKanarek I'm going to close, let me know if you have another issue here, thanks!

If this keeps coming up, we may need to figure out some better error messaging here. I think it could be more clear what needs fixing: Are you missing a NuGet package?

Ran into the same problem after upgrading to VS 16.5. My error is

2>R8 : warning : Missing class: com.samsung.android.fingerprint.FingerprintManager$EnrollFinishListener
2>R8 : warning : Missing class: com.samsung.android.fingerprint.FingerprintIdentifyDialog$FingerprintListener
2>R8 : warning : Missing class: com.samsung.android.fingerprint.IFingerprintClient$Stub
2>R8 : error : Compilation can't be completed because some library classes are missing.

Probably to do with the Plugin.Fingerprint package we are using but still annoying. As I understand it's detecting a real problem but I don't understand why it didn't popup when I did a release build with 16.4 and R8.

Oh right, so we just need to track down the missing Nugets? Mine says this..
10>R8 : warning : Missing class: org.conscrypt.ConscryptHostnameVerifier
10>R8 : warning : Missing class: androidx.paging.PositionalDataSource

I usually figure out the missing ones by searching the web.

@clintonrocksmith in your case, I _think_ it might be one of these:

Hopefully, you are already using AndroidX.

But then I also found one of them is related to okhttp and to ignore it?

https://stackoverflow.com/questions/49880928/how-to-resolve-d8-warning-d8-type-org-conscrypt-conscrypt-was-not-found

Hopefully, you can _actually_ ignore it. Does that one cause the build to fail?

Thanks Jonathan for replying. We haven't moved to AndroidX as yet but will look to in the release after next. Our regression is massive.
We followed these instructions:-

Try setting your project back to the current recommended defaults. For example, remove all of the following properties from the .csproj file via Notepad:

AndroidEnableMultiDex
AndroidDexGenerator
AndroidLinkTool
AndroidDexTool

This will let Xamarin.Android pick the current latest default values.

Was this page helpful?
0 / 5 - 0 ratings