xamarin / AndroidSupportComponents

Xamarin bindings for Android Support libraries - For AndroidX see https://github.com/xamarin/AndroidX
MIT License
146 stars 56 forks source link

Build fails when using WorkManager and D8 #168

Open tranb3r opened 5 years ago

tranb3r commented 5 years ago

Xamarin.Android Version (eg: 6.0):

9.3.0.14

Operating System & Version (eg: Mac OSX 10.11):

Windows 10 1809

Support Libraries Version (eg: 23.3.0):

28.0.0.1

Describe your Issue:

Enabling D8 when using Workmanager causes Build to fail.

Steps to Reproduce (with link to sample solution if possible):

Add Xamarin.Android.Arch.Work.Runtime NuGet package and use the WorkManager to enqueue some worker. Enable D8 in android csproj (<AndroidDexTool>d8</AndroidDexTool>) R8 or Proguard is NOT enabled. Build fails.

You can use this sample to reproduce : https://github.com/JonDouglas/WorkManagerSample When enabling D8, build fails.

Include any relevant Exception Stack traces, build logs, adb logs:

R8 : warning : Missing class: android.arch.paging.PositionalDataSource R8 : error : Compilation can't be completed because some library classes are missing.

sgong-pdftron commented 5 years ago

Any update on this issue? I am having similar situation and trying to bind a library that is using Room, the exact same error (Missing class: android.arch.paging.PositionalDataSource) is showing up as well. And I cannot seem to find a package that contains this class. Thanks.

sgong-pdftron commented 5 years ago

Update: manually including the android.paging common jar (tested with common-1.0.1.jar) as EmbeddedJar in the binding library will create a successful build.

tranb3r commented 5 years ago

Xamarin.Firebase.JobDispatcher nuget has been removed from nuget.org. So I guess WorkManager is now the only way to schedule a job properly. Anybody working on a fix for this issue ? It's really becoming a blocker for me...

tranb3r commented 5 years ago

I've opened this ticket more than 2 months ago, and so far it's been totally ignored. Is this component maintained ? How are we suppose to use it if build fails when using it ?!?

riteshdubey86 commented 5 years ago

Has someone get the solution of this problem. We are getting this error in release mode.

tranb3r commented 5 years ago

I've managed to find a workaround (even if I do not fully understand why it works...):

  1. Add this to your proguard.cfg
    -keep public class android.arch.lifecycle.ProcessLifecycleOwnerInitializer { *; }
    -keep public class androidx.work.impl.** { *; }
    -dontwarn android.arch.paging.PositionalDataSource
  2. Add this to your LinkerConfig.xml
    <assembly fullname="Xamarin.Android.Arch.Work.Runtime">
    <type fullname="*" />
    </assembly>

    @riteshdubey86, hope this helps!

martijn-nap commented 5 years ago

Same problem here. The workaround provided by @tranb3r isn't working for me. "Compilation can't be completed because some library classes are missing."

"Proguard configuration file 'C:\Users\user.nuget\packages\xamarin.android.arch.persistence.room.runtime\1.1.1.1\build....\proguard\proguard.txt' was not found.'"

"Proguard configuration file 'C:\Users\user.nuget\packages\xamarin.android.arch.work.runtime\1.0.0\build....\proguard\proguard.txt'"

"Missing class: android.arch.paging.PositionalDataSource"

using NuGet Xamarin.Android.Arch.Work.Runtime

diegostamigni commented 5 years ago

@martijn-nap just add -keep public class android.arch.paging.** { *; } to your proguard cfg

martijn-nap commented 5 years ago

@martijn-nap just add -keep public class android.arch.paging.** { *; } to your proguard cfg

That does not (re)solve anything... Same errors still happen

diegostamigni commented 5 years ago

That's what I have and works fine to me @martijn-nap. Try adding the notwarn too, such that you end up with:

-keep class android.arch.paging.** { *; } 
-dontwarn android.arch.paging.**
martijn-nap commented 5 years ago

Removes the warning (ofcourse) but makes the App startup and instantly crashes. Also adds a lot of other errors... err

diegostamigni commented 5 years ago

Removes the warning (ofcourse) but makes the App startup and instantly crashes. Also adds a lot of other errors... err

It might be for other reasons tho, following is my proguard cfg I use to one of my projects where I have workers: Proguard.txt

Try it and let us know @martijn-nap

martijn-nap commented 5 years ago

Works with your file! Going to narrow it down now to see what the missing rule is.

EDIT: thanks for the help! Problem was that -keep class androidx.work.impl.** { *; } was missing.

diegostamigni commented 5 years ago

Yeah, you're missing something else in your proguard cfg. Afaik it should tell you if you check carefully your build log tho. After all, I've been populating my cfg from there (+ the standard Xamarin suggested ones)

3akat commented 5 years ago

@martijn-nap @diegostamigni Guys, can you please create a demo app where the issue is fixed with your workaround? I've tried but no success. Would really appreciate!

tranb3r commented 5 years ago

@Redth Any progress on this issue ?

thudugala commented 4 years ago

I'm getting MSB6006: "java.exe" exited with code 1.

VS: 16.3.1 Dex: D8 shrinker: R8

after setting proguard.cfg and LinkerConfig.xml

2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.D8.targets(81,5): error MSB6006: "java.exe" exited with code 1.

Redth commented 4 years ago

The proguard warnings should be fixed in: https://www.nuget.org/packages/Xamarin.Android.Arch.Work.Runtime/1.0.0.3 (which should pull in a newer version of persistence packages with similar fixes).

Please let us know if this resolves the issue.

thudugala commented 4 years ago

issue is fixed

tranb3r commented 4 years ago

No more warnings but I still need to add some rules to my proguard.cfg in order for it to work.

guianm commented 4 years ago

Error persists when using R8 shrink.

thudugala commented 4 years ago

Getting error

2>R8 : warning : Missing class: android.arch.paging.PositionalDataSource 2>R8 : error : Compilation can't be completed because some library classes are missing.

VS: 16.3.8 Xamarin.Forms: 4.3.0.947036 Dex: D8 shrinker: R8

clintonrocksmith commented 4 years ago

I turned off MultiDex and it fixed it for me

clintonrocksmith commented 4 years ago

Morning, after updating to Visual Studio 16.5 we again have build issues. This is on Mac and Windows. Using R8, I get this type of output:- 1>R8 : warning : Missing class: org.conscrypt.ConscryptHostnameVerifier 1>R8 : warning : Missing class: android.arch.paging.PositionalDataSource 1>R8 : error : Compilation can't be completed because some library classes are missing.

And when I don't, it has trouble seeing *.png for some reason

I'll do more investigation to try and figure out what is going on. We have a complex application from XF1.x so it could be anything.

RobTF commented 4 years ago

Hi, yes we have the same issue as of 16.5.1 and still see it on 16.5.2.

Error is; Missing class: android.arch.paging.PositionalDataSource

Something has definitely broken, am happy to downgrade to 16.4.x temporarily if there is away to do that?

ijunaid commented 4 years ago

Facing same issues after updating visual studio on Mac.