xamarin / AndroidSupportComponents

Xamarin bindings for Android Support libraries - For AndroidX see https://github.com/xamarin/AndroidX

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build fails when using WorkManager and D8

tranb3r opened this issue · comments

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.

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.

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.

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

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

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

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
  1. Add this to your LinkerConfig.xml
<assembly fullname="Xamarin.Android.Arch.Work.Runtime">
  <type fullname="*" />
</assembly>

@riteshdubey86, hope this helps!

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

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

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

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

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

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

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

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.

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)

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

@Redth Any progress on this issue ?

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.

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.

issue is fixed

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

Error persists when using R8 shrink.

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

I turned off MultiDex and it fixed it for me

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.

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?

Facing same issues after updating visual studio on Mac.