Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Android: Unable to instantiate activity ComponentInfo

I am receiving this error when trying to launch a Xamarin forms application on Android from a text message URL. I have been following the steps noted in THIS article.

Here the application node in my AppManifest.xml

<application android:label="Label A">
  <activity android:icon="@drawable/Icon" android:label="LabelB" android:name=".MainActivity">
    <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="superduperapp" />
    </intent-filter>
  </activity>
</application>

According to the article I need to do something with intent objects to get the OnCreate override to fire but I think I am not matching something up right with my manifest and the naming convention for a class I created below.

[Activity(Label = "urlentryclass")]
public class OpenFromURI : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        Intent outsideIntent = Intent;
        var x = Intent.Data.EncodedAuthority;
    }
}

So, with the above code added to my xamarin solution I also have a webpage with the code below..

<a href="superduperapp://QueryStringParamsGoHere"></a>

and when i click the link above from my mobile browser it touches the mobile app because I get the error below

MyApp.Mobile.Droid.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "MyApp.Mobile.Droid.MainActivity" on path: DexPathList[[zip file "/data/app/MyApp.Mobile.Droid-1/base.apk"],nativeLibraryDirectories=[/data/app/MyApp.Mobile.Droid-1/lib/arm64, /data/app/MyApp.Mobile.Droid-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]] occurred
like image 941
XamDev89 Avatar asked Apr 20 '18 04:04

XamDev89


1 Answers

MyApp.Mobile.Droid.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "MyApp.Mobile.Droid.MainActivity"

Xamarin.Android, by default, generates the Java wrappers using MD5-based class names to avoid Java class name clashing, such as:

md579731053346ff64fcf21847b09163ce1.MainActivity 

You have hard-coded a android:name=".MainActivity" in your manifest but the generated class will be MD5-based by default.

Open up your MainActivity and within the ActivityAttribute on your MainActvity class, add a fully qualified name within a Name parameter of that attribute, this will force the Xamarin.Android build process to use a Java-class name of your choosing vs. the MD5-based one and thus it will match your manifest entry.

Example:

[Activity(Name = "MyApp.Mobile.Droid.MainActivity", Label = "MySuperDuperApp", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity
{
   ~~~
like image 182
SushiHangover Avatar answered Jan 02 '23 23:01

SushiHangover