Search code examples
c#androidmobilemaui

Maui Project Unable to instantiate activity ComponentInfo


Java.Lang.RuntimeException: 'Unable to instantiate activity ComponentInfo{TCRM_Service.TCRM_Service/TCRM_Service.MainActivity}: '
java.lang.ClassNotFoundException: 'Didn't find class "TCRM_Service.MainActivity" on path: DexPathList
[
    [zip file "/data/app/~~C_BfwTgdTmI7Q2CVHS4Avw==/TCRM_Service.TCRM_Service-IWq-WarhbPCJ22s36wnDpw==/base.apk"],
    nativeLibraryDirectories=
    [
        /data/app/~~C_BfwTgdTmI7Q2CVHS4Avw==/TCRM_Service.TCRM_Service-IWq-WarhbPCJ22s36wnDpw==/lib/x86_64,
        /data/app/~~C_BfwTgdTmI7Q2CVHS4Avw==/TCRM_Service.TCRM_Service-IWq-WarhbPCJ22s36wnDpw==/base.apk!/lib/x86_64, 
        /system/lib64, 
        /system_ext/lib64
    ]
]

I am trying to get my app onto the google play store and keep running into this issue...

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="TCRM_Service" android:versionCode="1" android:versionName="1.0">
    <application android:allowBackup="true" android:icon="@mipmap/appicon" android:label="TCRM_Service">
        <activity android:name="TCRM_Service.MainActivity" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
</manifest>
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace TCRM_Service;

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
    }
}

I've tried renaming packages, using the onCreate feature, nothing worked.


Solution

  • To fix the issue, you can define MainActivity class like below:

    namespace TCRM_Service;
    
    [Activity(Name="TCRM_Service.MainActivity", Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
    public class MainActivity : MauiAppCompatActivity
    {
       ...
    }
    
    

    For more information, you can refer to the docs: Activity name.