xamarin / XamarinComponents

Plugins for Xamarin
MIT License
1.99k stars 696 forks source link

Guava missing classes? #776

Open guillermo-gerard opened 4 years ago

guillermo-gerard commented 4 years ago

I have installed the version 27.1.0 of xamarin.google.guava and I'm getting errors like this:

Fatal Exception: java.lang.NoClassDefFoundError Failed resolution of: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension; com.google.common.base.Throwables.getStackTraceAsString (Throwables.java:352)

As I can see in the crashlytics report, the invocation of this method comes from io.grpc.Status.toString (Status.java:551)

If I try to update guava to any newer version, then I've got another error (another missing class):

Java.Lang.NoClassDefFoundError: 'Failed resolution of: Lcom/google/common/base/Preconditions;'

thrown when I try to make a query to Firestore

Any ideas on what's missing? It appears that the binding is deleting those classes

Redth commented 4 years ago

This sounds kind of like something's getting linked away from your app, or never making it into the final dex in the first place.

Can you try and update to Xamarin.Google.Guava 27.1.0.3 and adding an explicit PackageReference to your app head project for that package?

It also could be that the .targets from the nuget package weren't being properly included in your app project, and so the actual <ReferenceJar Include="$(MSBuildThisFileDirectory)guava.jar" /> was not making it into the build, causing the actual .jar to be excluded from the app which could also cause this issue.

The newest nuget package uses buildTransitive/ as well so this shouldn't happen anymore as a transitive dependency in the future, but for now, adding an explicit reference to this package should help.

guillermo-gerard commented 4 years ago

Thank you for your answer Jonathan, and sorry for the delay, I was on vacations (lucky me, I know) I'm still using the old way to include packages, with packages.config. So, today I've tried to run the migration in all the projects in my solution but then I needed to also convert one PCL project to a shared one, and, well, that didn't end as expected, because I have some dependencies there which are not supported; so finally I've undone all the changes. Anyway, even if I eventually get the migration done and it works I don't fully understand what you are asking me to do. Are you telling me that I need to add something like: <package id="com.google.common.base.Preconditions" version="xxxxxx" targetFramework="xxxxxxx" /> ?

RedChops commented 4 years ago

At one point I was able to get my app to compile with the combination of Xamarin.Build.Download 0.7.1 and Guava 27.1.0, but I'm self-compiling the Play Services libraries off their androidx branch and applied a patch to allow XBD >0.8 to work. Unfortunately it seems like Guava is not at all compatible with XBD >0.7.1.

Compiling with Guava 27.1.0 gives me an error about a duplicate ListenableFuture class (probably something depends on the nuget package somewhere, reasonable). Bumping the version to 27.1.0.3 gives me a bunch of missing classes:

The first three are solved by downloading the Guava jar manually and bundling it in my Android project and setting the action to 'AndroidExternalJavaLibrary', which seems to mean that it's not getting downloaded through the normal build process.

The final missing class seems to be due to a dependency on some Google Conscrypt library that isn't provided anywhere. I tried to download the 'aar' from maven and bundle it in, but it looks like it's going to need an actual binding project, I'm going to try to put that together.

I can't exactly tell where this Conscrypt dependency is coming from, looking at https://mvnrepository.com/artifact/org.conscrypt/conscrypt-android/usages doesn't suggest it's used in a lot of places, so I'm not sure if it's a part of Guava or something else.

RedChops commented 4 years ago

Alright, I've tried a few permutations of build configs and made some findings. First, I've removed the hard dependency on Xamarin.Build.Download, so I'm assuming it's on version 0.9.0 right now. I'm not using any code shrinker right now.

  1. Guava 27.1.0.3, dex compiler 'dx': Application compiles just fine, on runtime I get a 'NoClassDefFoundError of 'Failed resolution of: Lcom/google/common/base/Preconditions;'
  2. Guava 27.1.0.3, dex compiler 'dx': Guava jar added, same as scenario 1.
  3. Guava 27.1.0.3, dex compiler 'd8': Application wont compile, missing classes as stated in above comment
  4. Guava 27.1.0.3, dex compiler 'd8': Guava jar manually added as stated above, now only 'com.conscrypt.ConscryptHostnameVerifier' is marked as missing.
  5. Guava 27.1.0, dex compiler 'd8': Application wont compile, gives an error of 'Program type already present: com.google.common.util.concurrent.ListenableFuture'
  6. Guava 27.1.0, dex compiler 'dx': Application compiles and runs completely without error.

Situation 5 probably makes sense, because Xamarin.Firebase.Firestore has a dependency on Xamarin.Google.Guava.ListenableFuture, but then I don't really understand why it works in situation 6 just by changing the dex compiler.

I also have to use the 'dx' compiler. If I leave multidex disabled, with Guava 27.1.0 I get the same error as situation 5, with Guava 27.1.0.3 I just get '"java.exe" exited with code 2.'

I hope this makes sense to the devs here. I took a little look at the bindings in this repo but nothing particularly stood out to me.

ifecdr commented 4 years ago

Has there been solutions to this issue? I also have the same issue after running some updates to the Firebase packages including firestore. Reverting the updates seems not to solve the build issues on my end so this needs to be escalated..

guillermo-gerard commented 4 years ago

I've just tried the last nuget available today (v28.2.0) and I've got the same error at runtime: Java.Lang.NoClassDefFoundError: 'Failed resolution of: Lcom/google/common/base/Preconditions;' No changes so far :(

renaud007 commented 3 years ago

I ve got the same problem after installing the latest version (v28). someone would like to help me?

ifecdr commented 3 years ago

I ve got the same problem after installing the latest version (v28). someone would like to help me?

Sorry to hear. It doesn't seem to me that they are working on the issue or even trying to fix it. I would suggest building a library around firebase rest apis which is what I did and doing away with the native libraries. There may be some feature downside to that but at least you save yourself the trouble of dealing with these libraries and if you're not interested in doing that yourself there are nugget packages that are based on firebase rest apis. I hope this helps

RedChops commented 3 years ago

Still facing this unfortunately. Seems the only solution is to use Guava 27.1.0.1 where needed. Later versions may work, but I didn't feel like messing with it anymore.

jibinjerom commented 3 years ago

Still facing this unfortunately. Seems the only solution is to use Guava 27.1.0.1 where needed. Later versions may work, but I didn't feel like messing with it anymore.

It was good to know...I spent a lot of time to sort out this...nothing worked..This version works fine.