Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Class not found exceptions when using Cast Framework #431

Open
1 task done
janwiebe-jump opened this issue Feb 19, 2021 · 3 comments
Open
1 task done

Class not found exceptions when using Cast Framework #431

janwiebe-jump opened this issue Feb 19, 2021 · 3 comments
Assignees

Comments

@janwiebe-jump
Copy link

Xamarin.Android Version (eg: 6.0):

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

Windows 10

Google Play Services Version

  • GPS-FB with AndroidX dependencies (versions 119.0.0)

  • [] GPS-FB with Android.Support (legacy) dependencies (versions 71.yyyy.zz)

Describe your Issue

I am trying to implement Cast framework in my media player app, and am running into some issues.
I use Plugin.MediaManager as a media player, and that works quite well.

While running in debug mode, I first got the error

Java.Lang.NoSuchMethodError: 'No static method checkBuilderRequirement(Ljava/lang/Object;Ljava/lang/Class;)V in class Ldagger/internal/Preconditions; or its super classes (declaration of 'dagger.internal.Preconditions' appears in /data/app/com.companyname.castrepro-XX6pkXD9n959r2Dmgs8Opw==/base.apk)'

Then I added the Xamarin.Google.Dagger package.

After this, I get the following error:

'Failed resolution of: Lcom/google/android/datatransport/runtime/EncodedDestination;'
Java.Lang.NoClassDefFoundError
  Message=Failed resolution of: Lcom/google/android/datatransport/runtime/EncodedDestination;

If I set AndroidEnableDesugar to false, I get this build error:

Static interface methods are only supported starting with Android N (--min-api 24): androidx.browser.trusted.TrustedWebActivityDisplayMode androidx.browser.trusted.TrustedWebActivityDisplayMode.fromBundle(android.os.Bundle)

I have to set the minimum version to Oreo to be able to build again.
That's not acceptable for my client, and even then, I get the same error. So I reverted that.

As another try, I added the following package to check whether the exception would be solved.

<PackageReference Include="Xamarin.Google.Android.DataTransport.TransportRuntime">
      <Version>2.2.5</Version>
    </PackageReference>

That gives me a runtime crash:

02-19 11:53:44.316 E/AndroidRuntime(22645): FATAL EXCEPTION: pool-2-thread-1
02-19 11:53:44.316 E/AndroidRuntime(22645): Process: com.companyname.castrepro, PID: 22645
02-19 11:53:44.316 E/AndroidRuntime(22645): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/encoders/json/JsonDataEncoderBuilder;
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at com.google.android.datatransport.cct.zzc.<init>(SourceFile:2)
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at com.google.android.datatransport.cct.CctBackendFactory.create(SourceFile:4)
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at com.google.android.datatransport.runtime.backends.MetadataBackendRegistry.get(MetadataBackendRegistry.java:80)
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at com.google.android.datatransport.runtime.scheduling.DefaultScheduler.lambda$schedule$1(DefaultScheduler.java:70)
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at com.google.android.datatransport.runtime.scheduling.DefaultScheduler$$Lambda$1.run(Unknown Source:8)
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at com.google.android.datatransport.runtime.SafeLoggingExecutor$SafeLoggingRunnable.run(SafeLoggingExecutor.java:47)
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at java.lang.Thread.run(Thread.java:919)
02-19 11:53:44.316 E/AndroidRuntime(22645): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.encoders.json.JsonDataEncoderBuilder" on path: DexPathList[[zip file "/data/app/com.companyname.castrepro-9g2mnHYCv9sU4yUcxx1u1g==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.castrepro-9g2mnHYCv9sU4yUcxx1u1g==/lib/arm64, /data/app/com.companyname.castrepro-9g2mnHYCv9sU4yUcxx1u1g==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:230)
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
02-19 11:53:44.316 E/AndroidRuntime(22645): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

I was maybe missing the Xamarin.GooglePlayServices.Base. Installed it (it got updated to 117.6.0).
Same error.

Since the error DataTransport CCT installed the following package. It got updated.

<PackageReference Include="Xamarin.Google.Android.DataTransport.TransportBackendCct">
      <Version>2.3.3</Version>
    </PackageReference>

This doesn't solve my problem either.

Relevant information

Add relevant project settings from *.csproj file:

Packages used:

    <PackageReference Include="Plugin.CurrentActivity">
      <Version>2.1.0.4</Version>
    </PackageReference>
    <PackageReference Include="Plugin.MediaManager">
      <Version>1.0.8</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Forms" Version="5.0.0.1931" />
    <PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
    <PackageReference Include="Xamarin.Google.Dagger">
      <Version>2.27.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Cast.Framework">
      <Version>119.0.0</Version>
    </PackageReference>

Build settings (tools)

    <AndroidDexTool>d8</AndroidDexTool>
    <AndroidLinkTool>none</AndroidLinkTool>
    <AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
    <AndroidUseAapt2>true</AndroidUseAapt2>
    <AndroidEnableDesugar>true</AndroidEnableDesugar>

Minimal Repro Code Sample

I have a sample project at https://github.com/janwiebe-jump/cast-repro

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

Run the code, and see the error coming.

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

I see the following D8 related warnings in the build log:

2>  Warning in obj\Debug\100\lp\109\jl\classes.jar:androidx/browser/trusted/ConnectionHolder.class:
2>    Type `androidx.concurrent.futures.CallbackToFutureAdapter` was not found, it is required for default or static interface methods desugaring of `com.google.common.util.concurrent.ListenableFuture androidx.browser.trusted.ConnectionHolder.getServiceWrapper()`
2>  Warning in obj\Debug\100\lp\109\jl\classes.jar:androidx/browser/browseractions/BrowserServiceFileProvider.class:
2>    Type `androidx.concurrent.futures.ResolvableFuture` was not found, it is required for default or static interface methods desugaring of `androidx.concurrent.futures.ResolvableFuture androidx.browser.browseractions.BrowserServiceFileProvider.saveBitmap(android.content.Context, android.graphics.Bitmap, java.lang.String, int)`
2>  Warning in obj\Debug\100\lp\58\jl\bin\classes.jar:com/google/android/datatransport/cct/CCTDestination.class:
2>    Type `com.google.android.datatransport.Encoding` was not found, it is required for default or static interface methods desugaring of `void com.google.android.datatransport.cct.CCTDestination.<clinit>()`
2>  Warning in synthesized for lambda desugaring:
2>    Type `com.google.android.exoplayer2.trackselection.BufferSizeAdaptationBuilder$DynamicFormatFilter$-CC` was not found, it is required for default or static interface methods desugaring of `boolean com.google.android.exoplayer2.trackselection.-$$Lambda$BufferSizeAdaptationBuilder$DynamicFormatFilter$BH3m8KzNbxVGby6qwbUDLza1S04.isFormatAllowed(com.google.android.exoplayer2.Format, int, boolean)`
2>  Warning in synthesized for lambda desugaring:
2>    Type `com.google.android.exoplayer2.upstream.HttpDataSource$-CC` was not found, it is required for default or static interface methods desugaring of `boolean com.google.android.exoplayer2.upstream.-$$Lambda$HttpDataSource$fz-i4cgBB9tTB1JUdq8hmlAPFIw.evaluate(java.lang.Object)`
2>  Warning in obj\Debug\100\lp\58\jl\bin\classes.jar:com/google/android/datatransport/cct/a/zzb$zzb.class:
2>    Type `com.google.firebase.encoders.ObjectEncoder` was not found, it is required for default or static interface methods desugaring of `com.google.android.datatransport.cct.a.zzb$zzb`
2>  Warning in obj\Debug\100\lp\58\jl\bin\classes.jar:com/google/android/datatransport/cct/CCTDestination.class:
2>    Type `com.google.android.datatransport.runtime.EncodedDestination` was not found, it is required for default or static interface methods desugaring of `com.google.android.datatransport.cct.CCTDestination`
2>  Warning in obj\Debug\100\lp\58\jl\bin\classes.jar:com/google/android/datatransport/cct/a/zzb.class:
2>    Type `com.google.firebase.encoders.config.Configurator` was not found, it is required for default or static interface methods desugaring of `com.google.android.datatransport.cct.a.zzb`
2>  Warning in synthesized for lambda desugaring:
2>    Type `androidx.concurrent.futures.CallbackToFutureAdapter$Resolver` was not found, it is required for default or static interface methods desugaring of `androidx.browser.trusted.-$$Lambda$ConnectionHolder$AU_vyFTWietXr1KAI5OuiE799PQ`
2>Done executing task "D8".
@janwiebe-jump
Copy link
Author

Well, at least I figured it out.
I added the Xamarin.Firebase.Messaging package, that contains the JsonDataEncoderBuilder and pulls in other necessary packages.
Now I am able to build. Connect my device to chromecast, and start playing a media file.
However, the dependencies of the Xamarin.GooglePlayServices.Cast.Framework package don't seem correct. I had to spend hours to figure this out.

    <PackageReference Include="Plugin.CurrentActivity">
      <Version>2.1.0.4</Version>
    </PackageReference>
    <PackageReference Include="Plugin.MediaManager">
      <Version>1.0.8</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Messaging">
      <Version>121.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Forms" Version="5.0.0.1931" />
    <PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
    <PackageReference Include="Xamarin.Google.Dagger">
      <Version>2.27.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Cast.Framework">
      <Version>119.0.0</Version>
    </PackageReference>

@moljac
Copy link
Member

moljac commented Feb 19, 2021

@janwiebe-jump

Thanks for your feedback. Appreciated.

Yes. Dependencies can be hell. The number of artifacts grows and the number of nuget maintainers decreases. 😄

The reason dependencies might not be right and manual addition is necessary is simple - at the time of creating bindings the latest versions are used and if something changes in dependency chain it can break things.

The common problem is that Dagger must be manually added (latest version) and recently DataTransport too.

I plan to update tons of bindings in XamarinComponents next week, but that is tons of work.

Can I add this Cast sample to our samples, please?

We need it as much as possible in order to have large testing surface.

@janwiebe-jump
Copy link
Author

Hi @moljac,

Thanks for your quick reply! Much appreciated!

Yes. Dependencies can be hell. The number of artifacts grows and the number of nuget maintainers decreases. 😄

The reason dependencies might not be right and manual addition is necessary is simple - at the time of creating bindings the latest versions are used and if something changes in dependency chain it can break things.

The common problem is that Dagger must be manually added (latest version) and recently DataTransport too.

Thanks for your explanation! I didn't add DataTransport manually though, I use the transitive dependency from Dagger (I guess) and it works. So I assume I am safe now?

I plan to update tons of bindings in XamarinComponents next week, but that is tons of work.

That would be nice!

Can I add this Cast sample to our samples, please?
We need it as much as possible in order to have large testing surface.

Yes, of course! It is not very clean code though, just as quick and dirty to test my use case.

Thanks again!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants