Attempting to get Casting to work in .Net Maui on android, and Seems that regardless of what I do. When I Initialize the CastContext inthe OnCreate method of the Android Main Activity, I get the error that it fails to Initialize. If I dig A little further, it says that the path to the OptionsProvider can not be found, but I'm at a loss. Seems that regardless of what Namespace I put on the CastOptions Class it is the same error.
Here is the full error message;
{Java.Lang.IllegalStateException: Failed to initialize CastContext. ---> Java.Lang.ClassNotFoundException: MauiApp3.CastOptionsProvider ---> Java.Lang.ClassNotFoundException: Didn't find class "MauiApp3.CastOptionsProvider" on path: DexPathList[[zip file "/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk"],nativeLibraryDirectories=[/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/lib/arm64, /data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] --- End of managed Java.Lang.ClassNotFoundException stack trace ---java.lang.ClassNotFoundException: Didn't find class "MauiApp3.CastOptionsProvider" on path: DexPathList[[zip file "/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk"],nativeLibraryDirectories=[/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/lib/arm64, /data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:536) at java.lang.Class.forName(Class.java:467) at com.google.android.gms.cast.framework.CastContext.zzf(com.google.android.gms:play-services-cast-framework@@21.2.0:7) at com.google.android.gms.cast.framework.CastContext.getSharedInstance(com.google.android.gms:play-services-cast-framework@@21.2.0:15) at crc64e73e5e987e2fb5cd.MainActivity.n_onCreate(Native Method) at crc64e73e5e987e2fb5cd.MainActivity.onCreate(MainActivity.java:39) at android.app.Activity.performCreate(Activity.java:8591) at android.app.Activity.performCreate(Activity.java:8570) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8762) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) --- End of managed Java.Lang.ClassNotFoundException stack trace ---java.lang.ClassNotFoundException: Didn't find class "MauiApp3.CastOptionsProvider" on path: DexPathList[[zip file "/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk"],nativeLibraryDirectories=[/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/lib/arm64, /data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:536) at java.lang.Class.forName(Class.java:467) at com.google.android.gms.cast.framework.CastContext.zzf(com.google.android.gms:play-services-cast-framework@@21.2.0:7) at com.google.android.gms.cast.framework.CastContext.getSharedInstance(com.google.android.gms:play-services-cast-framework@@21.2.0:15) at crc64e73e5e987e2fb5cd.MainActivity.n_onCreate(Native Method) at crc64e73e5e987e2fb5cd.MainActivity.onCreate(MainActivity.java:39) at android.app.Activity.performCreate(Activity.java:8591) at android.app.Activity.performCreate(Activity.java:8570) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8762) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) --- End of inner exception stack trace --- --- End of managed Java.Lang.ClassNotFoundException stack trace ---java.lang.ClassNotFoundException: MauiApp3.CastOptionsProvider at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:536) at java.lang.Class.forName(Class.java:467) at com.google.android.gms.cast.framework.CastContext.zzf(com.google.android.gms:play-services-cast-framework@@21.2.0:7) at com.google.android.gms.cast.framework.CastContext.getSharedInstance(com.google.android.gms:play-services-cast-framework@@21.2.0:15) at crc64e73e5e987e2fb5cd.MainActivity.n_onCreate(Native Method) at crc64e73e5e987e2fb5cd.MainActivity.onCreate(MainActivity.java:39) at android.app.Activity.performCreate(Activity.java:8591) at android.app.Activity.performCreate(Activity.java:8570) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8762) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)Caused by: java.lang.ClassNotFoundException: Didn't find class "MauiApp3.CastOptionsProvider" on path: DexPathList[[zip file "/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk"],nativeLibraryDirectories=[/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/lib/arm64, /data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 23 more --- End of managed Java.Lang.ClassNotFoundException stack trace ---java.lang.ClassNotFoundException: MauiApp3.CastOptionsProvider at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:536) at java.lang.Class.forName(Class.java:467) at com.google.android.gms.cast.framework.CastContext.zzf(com.google.android.gms:play-services-cast-framework@@21.2.0:7) at com.google.android.gms.cast.framework.CastContext.getSharedInstance(com.google.android.gms:play-services-cast-framework@@21.2.0:15) at crc64e73e5e987e2fb5cd.MainActivity.n_onCreate(Native Method) at crc64e73e5e987e2fb5cd.MainActivity.onCreate(MainActivity.java:39) at android.app.Activity.performCreate(Activity.java:8591) at android.app.Activity.performCreate(Activity.java:8570) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8762) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)Caused by: java.lang.ClassNotFoundException: Didn't find class "MauiApp3.CastOptionsProvider" on path: DexPathList[[zip file "/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk"],nativeLibraryDirectories=[/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/lib/arm64, /data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 23 more --- End of inner exception stack trace --- at Java.Interop.JniEnvironment.StaticMethods.CallStaticObjectMethod(JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:line 21452 at Java.Interop.JniPeerMembers.JniStaticMethods.InvokeObjectMethod(String encodedMember, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniStaticMethods.cs:line 165 at Android.Gms.Cast.Framework.CastContext.GetSharedInstance(Context context, IExecutor executor) in C:\a_work\1\s\generated\com.google.android.gms.play-services-cast-framework\obj\Release\net6.0-android31.0\generated\src\Android.Gms.Cast.Framework.CastContext.cs:line 413 at MauiApp3.MainActivity.InitializeCastContextAsync(Context context) in C:\Users\josep\source\repos\MauiApp3\MauiApp3\Platforms\Android\MainActivity.cs:line 29 at MauiApp3.MainActivity.OnCreate(Bundle savedInstanceState) in C:\Users\josep\source\repos\MauiApp3\MauiApp3\Platforms\Android\MainActivity.cs:line 20 at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.App.Activity.cs:line 3082 at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 125 --- End of managed Java.Lang.IllegalStateException stack trace ---java.lang.IllegalStateException: Failed to initialize CastContext. at com.google.android.gms.cast.framework.CastContext.zzf(com.google.android.gms:play-services-cast-framework@@21.2.0:11) at com.google.android.gms.cast.framework.CastContext.getSharedInstance(com.google.android.gms:play-services-cast-framework@@21.2.0:15) at crc64e73e5e987e2fb5cd.MainActivity.n_onCreate(Native Method) at crc64e73e5e987e2fb5cd.MainActivity.onCreate(MainActivity.java:39) at android.app.Activity.performCreate(Activity.java:8591) at android.app.Activity.performCreate(Activity.java:8570) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8762) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)Caused by: java.lang.ClassNotFoundException: MauiApp3.CastOptionsProvider at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:536) at java.lang.Class.forName(Class.java:467) at com.google.android.gms.cast.framework.CastContext.zzf(com.google.android.gms:play-services-cast-framework@@21.2.0:7) ... 19 moreCaused by: java.lang.ClassNotFoundException: Didn't find class "MauiApp3.CastOptionsProvider" on path: DexPathList[[zip file "/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk"],nativeLibraryDirectories=[/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/lib/arm64, /data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 23 more --- End of managed Java.Lang.IllegalStateException stack trace ---java.lang.IllegalStateException: Failed to initialize CastContext. at com.google.android.gms.cast.framework.CastContext.zzf(com.google.android.gms:play-services-cast-framework@@21.2.0:11) at com.google.android.gms.cast.framework.CastContext.getSharedInstance(com.google.android.gms:play-services-cast-framework@@21.2.0:15) at crc64e73e5e987e2fb5cd.MainActivity.n_onCreate(Native Method) at crc64e73e5e987e2fb5cd.MainActivity.onCreate(MainActivity.java:39) at android.app.Activity.performCreate(Activity.java:8591) at android.app.Activity.performCreate(Activity.java:8570) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8762) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)Caused by: java.lang.ClassNotFoundException: MauiApp3.CastOptionsProvider at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:536) at java.lang.Class.forName(Class.java:467) at com.google.android.gms.cast.framework.CastContext.zzf(com.google.android.gms:play-services-cast-framework@@21.2.0:7) ... 19 moreCaused by: java.lang.ClassNotFoundException: Didn't find class "MauiApp3.CastOptionsProvider" on path: DexPathList[[zip file "/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk"],nativeLibraryDirectories=[/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/lib/arm64, /data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 23 more}
I have the Path in the Metadata for the android Manifest like here;
<application android:allowBackup="true" android:supportsRtl="true">
<meta-data android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME" android:value="MauiApp3.CastOptionsProvider" />
and I'm Initializing the Context here.
private void InitializeCastContextAsync(Context context)
{
// Define the executor
IExecutor executor = AsyncTask.ThreadPoolExecutor;
// Call the asynchronous method to get the CastContext instance
Android.Gms.Tasks.Task castContextTask = CastContext.GetSharedInstance(context, executor);
// Add a continuation task to handle completion
castContextTask.AddOnCompleteListener(new OnCompleteListener(task =>
{
if (task.IsSuccessful)
{
// CastContext is initialized
var castContext = (CastContext)task.Result;
// Do something with castContext...
}
else
{
// Handle initialization failure
Exception exception = task.Exception;
// Log or display error...
}
}));
}
Lastly here is the CastOptionsProvider.
using Android.Content;
using Android.Gms.Cast.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace com.companyname.mauiapp3 <-- I keep changing this to try to see if that Java error ever changes.
{
public class CastOptionsProvider : Java.Lang.Object, IOptionsProvider
{
public CastOptions GetCastOptions(Context appContext)
{
var options = new CastOptions.Builder()
.SetReceiverApplicationId("7AA05E47")
.Build();
return options;
}
//public IPackageChannel GetCastChannel(string channelId)
//{
// return null;
//}
public IList<SessionProvider> GetAdditionalSessionProviders(Context appContext)
{
return null;
}
}
}
I made the changes as mentioned to match the Package name and its the same error;
{Java.Lang.IllegalStateException: Failed to initialize CastContext. ---> Java.Lang.ClassNotFoundException: com.companyname.mauiapp3.CastOptionsProvider ---> Java.Lang.ClassNotFoundException: Didn't find class "com.companyname.mauiapp3.CastOptionsProvider" on path: DexPathList[[zip file "/data/app/~~e4NAlnd0xGIU7m0aJHvm4Q==/com.companyname.mauiapp3-RJaoXOgIxunzik9DWGGSgA==/base.apk"],nativeLibraryDirectories=[/data/app/~~e4NAlnd0xGIU7m0aJHvm4Q==/com.companyname.mauiapp3-RJaoXOgIxunzik9DWGGSgA==/lib/arm64, /data/app/~~e4NAlnd0xGIU7m0aJHvm4Q==/com.companyname.mauiapp3-RJaoXOgIxunzik9DWGGSgA==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] --- End of managed Java.Lang.ClassNotFoundException stack trace ---java.lang.ClassNotFoundException: Didn't find class "com.companyname.mauiapp3.CastOptionsProvider" on path: DexPathList[[zip file "/data/app/~~e4NAlnd0xGIU7m0aJHvm4Q==/com.companyname.mauiapp3-RJaoXOgIxunzik9DWGGSgA==/base.apk"],nativeLibraryDirectories=[/data/app/~~e4NAlnd0xGIU7m0aJHvm4Q==/com.companyname.mauiapp3-RJaoXOgIxunzik9DWGGSgA==/lib/arm64, /data/app/~~e4NAlnd0xGIU7m0aJHvm4Q==/com.companyname.mauiapp3-RJaoXOgIxunzik9DWGGSgA==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:536)
Adding the Oncomplete listner method
// Helper class to handle task completion
public class OnCompleteListener : Java.Lang.Object, IOnCompleteListener
{
private readonly Action<Android.Gms.Tasks.Task> _onComplete;
public OnCompleteListener(Action<Android.Gms.Tasks.Task> onComplete)
{
_onComplete = onComplete;
}
public void OnComplete(Android.Gms.Tasks.Task task)
{
_onComplete?.Invoke(task);
}
}
Uploading Project file..
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
<!-- Note for MacCatalyst:
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
<OutputType>Exe</OutputType>
<RootNamespace>MauiApp3</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!-- Display name -->
<ApplicationTitle>MauiApp3</ApplicationTitle>
<!-- App Identifier -->
<ApplicationId>com.companyname.mauiapp3</ApplicationId>
<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
<PackageReference Include="Xamarin.GooglePlayServices.Cast">
<Version>121.2.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.GooglePlayServices.Cast.Framework">
<Version>121.2.0</Version>
</PackageReference>
</ItemGroup>
</Project>
According to the error message:
Java.Lang.ClassNotFoundException: MauiApp3.CastOptionsProvider ---> Java.Lang.ClassNotFoundException: Didn't find class "MauiApp3.CastOptionsProvider" on path: DexPathList[[zip file "/data/app/~~hN1P4pOlf7nl5c94efSAZA==/com.MauiApp3-HGXXbCCME0AJRmBkjgKyGg==/base.apk"]
If you used <meta-data android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME" android:value="MauiApp3.CastOptionsProvider" />
directly, the class can't be found.
You can register it by the Android.Runtime.Register
at first. Such as:
[Register("MauiApp3/CastOptionsProvider")]
public class CastOptionsProvider : Java.Lang.Object, IOptionsProvider
And then declare it in the AndroidManifest.xml:
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true">
<meta-data android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="MauiApp3.CastOptionsProvider" />
</application>