You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决AndroidManifest.xml报android属性不允许、无法解析MainActivity类错误

Flutter项目AndroidManifest.xml属性报错及类无法识别问题求助

问题现象

  • 在main/AndroidManifest.xml文件中出现大量报错,多数错误提示为Attribute android:** not allowed here,涉及的属性包括icon、launchMode、theme、configChanges、hardwareAccelerated、usesCleartextTraffic、windowSoftInputMode
  • 同时存在*Unresolved class '.MainActivity'*报错,详见附件截图
  • 该问题不阻碍应用构建和发布,但会导致部分功能无法正常使用
  • 新建空白Flutter计数器项目也会出现相同报错,更换不同设备、不同操作系统(Windows、Mac)新建Flutter项目问题仍复现,升级Android Studio到最新Arctic Fox 2020.3.1版本后问题未解决

环境检测结果

pub get、pub upgrade、pub outdated执行完成退出码均为0,flutter doctor -v检测无异常,结果如下:

[✓] Flutter (Channel master, 2.5.0-7.0.pre.105, on Mac OS X 10.15.7 19H1323 darwin-x64, locale nb-NO)
• Flutter version 2.5.0-7.0.pre.105 at /Users/christianottoruge/flutter
• Upstream repository 为Flutter官方仓库
• Framework revision a2e33dec7c (8 hours ago), 2021-08-16 22:51:16 -0700
• Engine revision 7dc8eba6ae
• Dart version 2.15.0 (build 2.15.0-15.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/christianottoruge/Library/Android/sdk
• Platform android-30, build-tools 31.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.0.1, Build version 12A7300
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter、Dart插件均已正常安装
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.131
• No issues found!

已尝试的解决方法(均未生效)

  • 关闭后重新打开AndroidManifest文件
  • 执行File -> Invalidate caches/Restart
  • 设置File -> Project Structure -> Project SDK为“Android API 29 platform”
  • 清理项目后重新构建

关联文件内容

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test_test_test.test_test_test">

   <application
        android:label="test_test_test"
        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">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

MainActivity.kt

文件位于app/src/main/kotlin/test_test_test/test_test_test/路径下,项目不存在MainActivity.xml文件:

package com.test_test_test.test_test_test

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

求助内容

请问有什么方案可以解决该问题?

内容的提问来源于stack exchange,提问作者CORals

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.08 05:42:03