0

I'm trying to get deep links to work for my maui android app but when I click to open the link with the app I get this error:

Java.Lang.RuntimeException: 'Unable to instantiate activity ComponentInfo{app.mydomain/MyApp.Client.MAUI.MainActivity}:
java.lang.ClassNotFoundException: Didn't find class "MyApp.Client.MAUI.MainActivity" 
on path: DexPathList[[zip file "/data/app/~~0C9vYHAHNOr9CaB4f63clQ==/app.mydomain-YYQ6ZPc3-KSVnF8_VcuQVQ==/base.apk"],
nativeLibraryDirectories=[/data/app/~~0C9vYHAHNOr9CaB4f63clQ==/app.mydomain-YYQ6ZPc3-KSVnF8_VcuQVQ==/lib/arm64, 
/data/app/~~0C9vYHAHNOr9CaB4f63clQ==/app.mydomain-YYQ6ZPc3-KSVnF8_VcuQVQ==/base.apk!/lib/arm64-v8a, /system/lib64, 
/system_ext/lib64]]'

My MainActivity.cs looks like this

namespace MyApp.Client.MAUI
{
 [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataScheme = "https", DataHost = "mydomain.app", DataPathPattern = "/.*", AutoVerify = true)]
public class MainActivity : MauiAppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
    }
    protected override void OnResume()
    {
        base.OnResume();

        Platform.OnResume(this);
    }
    protected override void OnNewIntent(Intent intent)
    {
        base.OnNewIntent(intent);

        var data = intent.DataString;

        if (intent.Action != Intent.ActionView) return;
        if (string.IsNullOrWhiteSpace(data)) return;

        var path = data.Replace(@"https://mydomain.app", "");
        //todo - handle path

        StartActivity(typeof(MainActivity));
    }
}

The intent filter in the AndroidManifest.xml is like so:

    <activity android:name="MyApp.Client.MAUI.MainActivity" android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" android:host="mydomain.app" android:pathPattern="/.*" />
        </intent-filter>
    </activity>
Jimmy
  • 2,191
  • 6
  • 25
  • 45
  • I did a test, but I couldn't reproduce this problem. Could you please post the steps of reproducing this problem? – Jessie Zhang -MSFT Nov 14 '22 at 09:07
  • @JessieZhang-MSFT the steps to reproduce are 1) create new maui blazor proj 2) update the two files as above 3) debug on physical android device and try and open a relevant link with the app – Jimmy Nov 15 '22 at 00:54

1 Answers1

1

I could reproduce your problem.

And I can resolve this problem by adding tag <application> inside of AndroidManifest.xml.

You can refer to the full code of AndroidManifest.xml on my side:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <uses-permission android:name="android.permission.INTERNET" />

      <application android:allowBackup="true"  android:supportsRtl="true" android:theme="@style/AppTheme" android:name="android.app.Application" android:debuggable="true" android:extractNativeLibs="true">
            <activity android:name="MauiBlazorApp.MainActivity" android:exported="true">
                  <intent-filter>
                        <action android:name="android.intent.action.VIEW" />
                        <category android:name="android.intent.category.DEFAULT" />
                        <category android:name="android.intent.category.BROWSABLE" />
                        <data android:scheme="https" android:host="mydomain.app" android:pathPattern="/.*" />
                  </intent-filter>
            </activity>
            
      </application>

</manifest>

Note: Remember to change the value of android:name(YourAppName) of your activity to yours.

<application android:name="YourAppName.MainActivity">
Jimmy
  • 2,191
  • 6
  • 25
  • 45
Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19
  • Thanks Jessie. My activity was actually already in an application tag. In your example code you have two application tags which stops the app from debugging entirely (without any error message). Comparing the two tags it turns out the android:name tag missing from the application tag (not the activity tag) is the issues. Please edit your answer to reflect this so I can accept it – Jimmy Nov 17 '22 at 01:10
  • Hi @Jimmy,sorry, I forgot to remove another `application ` tag. Thank you for the kind reminder. Now I have updated my answer. – Jessie Zhang -MSFT Nov 17 '22 at 01:15
  • Cheers, the app opens now without error but just to the root page, any ideas why I still can't get it to call the OnNewIntent action? – Jimmy Nov 17 '22 at 01:20
  • Hi @Jimmy, one problem, one thread. You can create a new thread for the new problem. I am willing to help you. :) – Jessie Zhang -MSFT Nov 17 '22 at 01:25