【问题标题】:Unresolved class 'MainActivity'未解决的类“MainActivity”
【发布时间】:2021-11-09 16:43:06
【问题描述】:

我尝试了各种方法来解决这个问题,但对我没有任何效果。 这是我在 AndroidManifest.xml 中有错误的地方:

 android:label="cartoon_magic"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
Attribute android:icon is not allowed here
Unresolved class 'MainActivity'
Attribute android:launchMode is not allowed here
Attribute android:theme is not allowed here
Attribute android:configChanges is not allowed here
Attribute android:hardwareAccelerated is not allowed here
Attribute android:windowSoftInputMode is not allowed here

我猜是 import io.flutter.embedding.android.FlutterActivity 有问题,但我不知道如何解决。

这是我的 MainActivity.kt

package com.example.cartoon_magic

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

这是项目的结构:

我完全糊涂了,不知道从哪个方向寻找问题。感谢您的帮助!

【问题讨论】:

    标签: android xml flutter mobile


    【解决方案1】:

    一个好的AndroidManifest.xml 文件看起来像这样

    ?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="your.package.name">
    
    <uses-permission android:name="android.permission.INTERNET" /> <!--Your permissions-->
    
    <application
            android:name=".common.MyApplication"
            android:allowBackup="true"
            android:hardwareAccelerated="true"
            android:icon="${appIcon}" <!--Link to your app icon-->
            ...
    <!--Activities go here-->
     <activity
                android:name=".view.activity.AgreementDetails"
                android:configChanges="locale|orientation|keyboardHidden"
                android:windowSoftInputMode="adjustResize" />
    
    </application>    
    
    </manifest>
    

    需要注意的重要事项是您是否在正确的标签内使用了正确的值,例如,&lt;application&gt; 标签中的属性在&lt;activity&gt; 标签内不起作用。如果您已关闭所有标签,也请四处看看。 您可以通过两种方式关闭标签。仔细看看不同的属性是怎么写的

    <activity android:label="xyz" android:orientation="landscape">
    // Your intent related parameters here
    </activity>
    

    或者

    <activity android:label="xyz" android:orientation="landscape"/> <!--Notice the tag is close inline here-->
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-29
    • 2019-07-21
    • 1970-01-01
    • 1970-01-01
    • 2019-09-23
    • 1970-01-01
    • 2018-03-06
    • 2017-05-27
    相关资源
    最近更新 更多