AndroidSupportComponents icon indicating copy to clipboard operation
AndroidSupportComponents copied to clipboard

Build fails when using WorkManager and D8

Open tranb3r opened this issue 5 years ago • 26 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.

tranb3r avatar Apr 30 '19 07:04 tranb3r

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 avatar May 31 '19 23:05 sgong-pdftron

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.

sgong-pdftron avatar Jun 05 '19 22:06 sgong-pdftron

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 avatar Jun 13 '19 11:06 tranb3r

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

tranb3r avatar Jul 04 '19 17:07 tranb3r

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

riteshdubey86 avatar Jul 17 '19 06:07 riteshdubey86

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!

tranb3r avatar Jul 17 '19 20:07 tranb3r

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 avatar Aug 14 '19 13:08 martijn-nap

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

diegostamigni avatar Aug 14 '19 13:08 diegostamigni

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

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

martijn-nap avatar Aug 14 '19 13:08 martijn-nap

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

diegostamigni avatar Aug 14 '19 13:08 diegostamigni

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

martijn-nap avatar Aug 14 '19 14:08 martijn-nap

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

diegostamigni avatar Aug 14 '19 14:08 diegostamigni

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.

martijn-nap avatar Aug 14 '19 14:08 martijn-nap

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)

diegostamigni avatar Aug 14 '19 14:08 diegostamigni

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

3akat avatar Aug 16 '19 10:08 3akat

@Redth Any progress on this issue ?

tranb3r avatar Sep 10 '19 08:09 tranb3r

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.

thudugala avatar Sep 26 '19 22:09 thudugala

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.

Redth avatar Oct 03 '19 16:10 Redth

issue is fixed

thudugala avatar Oct 06 '19 20:10 thudugala

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

tranb3r avatar Oct 07 '19 09:10 tranb3r

Error persists when using R8 shrink.

guianm avatar Oct 10 '19 13:10 guianm

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

thudugala avatar Nov 05 '19 20:11 thudugala

I turned off MultiDex and it fixed it for me

clintonrocksmith avatar Nov 08 '19 02:11 clintonrocksmith

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.

clintonrocksmith avatar Mar 24 '20 21:03 clintonrocksmith

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?

RobTF avatar Apr 01 '20 14:04 RobTF

Facing same issues after updating visual studio on Mac.

ijunaid avatar Apr 21 '20 17:04 ijunaid