【问题标题】:How to address "Attribute android: ** not allowed here" errors?如何解决“Attribute android: ** not allowed here”错误?
【发布时间】:2021-10-19 10:50:40
【问题描述】:

我意识到我的 main/AndroidManifest.xml 文件中有错误。他们中的大多数报告:“属性 android:** 此处不允许”(** = 图标、launchMode、主题、configChanges、hardwareAccelerated、usesCleartextTraffic 和 windowSoftInputMode)。还有一个错误:“未解析的类'.MainActivity'(见附件截图)。

这并不妨碍构建和发布应用程序,但某些功能无法正常工作。

我尝试创建一个新的、干净的颤振项目(计数水龙头),但得到了同样的错误。我尝试在另一台计算机甚至不同的操作系统(Windows 和 Mac)上创建一个新的颤振项目,但问题仍然存在。并且我更新到了最新的 Android Studio (Arctic Fox 2020.3.1)。

Pub 以退出代码 0 结束。 Pub 升级已完成,退出代码为 0。 Pub 已过时,退出代码为 0。 Flutter Doctor -v 报告:

[✓] Flutter(Channel master,2.5.0-7.0.pre.105,Mac OS X 10.15.7 19H1323 darwin-x64,locale nb-NO) • Flutter 版本 2.5.0-7.0.pre.105,位于 /Users/christianottoruge/flutter • 上游仓库https://github.com/flutter/flutter.git • 框架修订 a2e33dec7c(8 小时前),2021-08-16 22:51:16 -0700 • 引擎修订版 7dc8eba6ae • Dart 版本 2.15.0(构建 2.15.0-15.0.dev)

[✓] Android 工具链 - 为 Android 设备开发(Android SDK 版本 31.0.0) • Android SDK 位于 /Users/christianottoruge/Library/Android/sdk • 平台 android-30,构建工具 31.0.0 • Java 二进制文件位于:/Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java 版 OpenJDK 运行时环境(内部版本 11.0.10+0-b96-7281165) • 接受所有 Android 许可证。

[✓] Xcode - 为 iOS 和 macOS 开发 • Xcode 位于 /Applications/Xcode.app/Contents/Developer • Xcode 12.0.1,内部版本 12A7300 • CocoaPods 版本 1.10.1

[✓] Chrome - 为网络开发 • Chrome 位于 /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio(版本 2020.3) • Android Studio 位于 /Applications/Android Studio.app/Contents • Flutter 插件可以从以下位置安装: ??? https://plugins.jetbrains.com/plugin/9212-flutter • Dart 插件可以从以下位置安装: ??? https://plugins.jetbrains.com/plugin/6351-dart • Java 版 OpenJDK 运行时环境(内部版本 11.0.10+0-b96-7281165)

[✓] 已连接设备(1 个可用) • Chrome(网络) • chrome • web-javascript • Google Chrome 92.0.4515.131

• 未发现任何问题!

我已经关闭并重新打开了 AndoidManifest 文件。 我已经尝试过文件-> 使缓存无效/重新启动。 我已将 File -> Project Structure -> Project Project SDK 设置为“Android API 29 平台”。 我已经构建、清理并重建了项目。

我的 AndroidManifest 文件如下所示:

<?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>

错误消息如下所示:

Errors - screenshot

没有MainActivity.xml文件,但是有一个MainActivity.kt文件放在app/src/main/kotlin/test_test_test/test_test_test/下。

代码是:

package com.test_test_test.test_test_test

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

谁能帮我解决这个问题?

问候,克里斯蒂安

【问题讨论】:

    标签: android flutter android-studio android-activity android-manifest


    【解决方案1】:

    如果您还没有尝试过,这可能会有所帮助:关闭清单,然后在 Android Studio 中执行 File -> Sync Project with Gradle Files。

    【讨论】:

    • 我在文件下没有那个选项... 我的选项是“新建”、“打开...”、“配置文件或调试 APK”、“打开最近”、“关闭项目” 、“项目结构”、“文件属性”、“本地历史记录”、“全部保存”、“从磁盘重新加载全部”、“使缓存无效/重新启动”、“管理 IDE 设置”、“新建项目设置”、“导出” 、“打印”、“添加到收藏夹”和“省电模式”...
    • 在这种情况下,这可能会有所帮助:stackoverflow.com/a/64119176/4862855
    • 我似乎错过了菜单选项,因为我试图在项目视图中输入菜单。解决方法是先在项目视图中找到Android Manifest文件,然后选择右上角的“Open for editing in Android Studio”。然后菜单选项可用,我也可以与 Gradle 文件同步。
    【解决方案2】:

    感谢 @joachimwedin 让我走上正轨。

    build.gradle 文件和文件 -> 项目设置 -> 模块 -> 依赖项“Module SDK”存在问题,未正确设置。我还在 build.gradle 中将“GradleException()”更改为“FileNotFoundException()”。 详情请参阅:https://github.com/flutter/flutter/issues/29608#issuecomment-548649907。在 File -> Invalidate Caches / Restart 之后,这暂时消除了我所有的 androidManifest 错误 - 但随后它们又返回了。

    为我解决的问题是将包名称添加到“.MainActivity”的位置。结果是:“'package'.MainActivity”。错误已消失,问题已解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-23
      • 2018-04-30
      • 2021-01-21
      • 1970-01-01
      • 2023-02-20
      • 2021-11-03
      • 1970-01-01
      • 2021-12-12
      相关资源
      最近更新 更多