Skip to content

R8 throws an error when code shrinker is set to none #4416

Closed

Description

@PawKanarek

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: OneSignal/OneSignal-Xamarin-SDK#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.

Activity

  1. added
    Area: App+Library Build
    on Mar 18, 2020
  2. Anil-R commented on Mar 18, 2020

    @Anil-R

    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.

  3. PawKanarek commented on Mar 18, 2020

    @PawKanarek
    Author

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

  4. gugavaro commented on Mar 18, 2020

    @gugavaro
    Contributor

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

  5. jonathanpeppers commented on Mar 18, 2020

    @jonathanpeppers
    Member

    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.

  6. jonathanpeppers commented on Mar 18, 2020

    @jonathanpeppers
    Member

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

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

  7. PawKanarek commented on Mar 18, 2020

    @PawKanarek
    Author

    @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.

  8. jonathanpeppers commented on Mar 18, 2020

    @jonathanpeppers
    Member

    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.

  9. PawKanarek commented on Mar 18, 2020

    @PawKanarek
    Author

    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?

  10. jonathanpeppers commented on Mar 19, 2020

    @jonathanpeppers
    Member

    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...

  11. added this to the Under Consideration milestone on Mar 19, 2020
  12. jonathanpeppers commented on Mar 19, 2020

    @jonathanpeppers
    Member

    @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?

  13. GuidoNeele commented on Mar 23, 2020

    @GuidoNeele

    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.

  14. clintonrocksmith commented on Mar 24, 2020

    @clintonrocksmith

    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

  15. jonathanpeppers commented on Mar 25, 2020

    @jonathanpeppers
    Member
  16. clintonrocksmith commented on Mar 25, 2020

    @clintonrocksmith

    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.

  17. ghost locked as resolved and limited conversation to collaborators on Jun 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library Build

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions