Maui Project 无法实例化活动 ComponentInfo

问题描述 投票:0回答:1

Java.Lang.RuntimeException:'无法实例化活动 ComponentInfo{TCRM_Service.TCRM_Service/TCRM_Service.MainActivity}:java.lang.ClassNotFoundException:在路径上找不到类“TCRM_Service.MainActivity”:DexPathList[[zip 文件“/data” /app/~~C_BfwTgdTmI7Q2CVHS4Avw==/TCRM_Service.TCRM_Service-IWq-WarhbPCJ22s36wnDpw==/base.apk"],nativeLibraryDirectories=[/data/app/~~C_BfwTgdTmI7Q2CVHS4Avw==/TCRM_Service.TCRM_Service-IWq-WarhbPCJ22s 36wnDpw==/lib /x86_64, /data/app/~~C_BfwTgdTmI7Q2CVHS4Avw==/TCRM_Service.TCRM_Service-IWq-WarhbPCJ22s36wnDpw==/base.apk!/lib/x86_64, /system/lib64, /system_ext/lib64]]'

我正在尝试将我的应用程序放到谷歌游戏商店并不断遇到这个问题......

<?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.
c# android mobile maui
1个回答
0
投票

要解决此问题,您可以定义

MainActivity
类,如下所示:

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
{
   ...
}

更多信息,您可以参考文档:活动名称

© www.soinside.com 2019 - 2024. All rights reserved.