如何解决 "Attribute android: ** not allowed here" 错误?

3

我意识到我的主/AndroidManifest.xml文件中存在错误。其中大部分报告:“此处不允许使用属性android:**”(** = icon,launchMode,theme,configChanges,hardwareAccelerated,usesCleartextTraffic和windowSoftInputMode)。还有一个错误:“未解析的类'.MainActivity'(请参见附加的截图)。

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

我尝试创建一个新的干净的flutter项目(计算点击次数),但仍然出现相同的错误。我尝试在不同的计算机上甚至在不同的操作系统上(Windows和Mac)创建一个新的flutter项目,但问题仍然存在。并且我更新到了最新的Android Studio(Arctic Fox 2020.3.1)。

Pub get完成,退出码为0。 Pub upgrade完成,退出码为0。 Pub outdated完成,退出码为0。 Flutter doctor -v报告:

[✓] Flutter(主频道,2.5.0-7.0.pre.105版本,在Mac OS X 10.15.7 19H1323 darwin-x64上,地区为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 Runtime Environment (build 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 - 为 Web 进行开发 • 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 Runtime Environment (build 11.0.10+0-b96-7281165)

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

• 未发现问题!

我已经关闭并重新打开了AndoidManifest文件。 我尝试了文件->无效缓存/重启。 我将文件->项目结构->项目项目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 - 截图

没有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() {
}

有谁能帮我解决这个问题吗?

诚挚的问候,克里斯蒂安

2个回答

1
如果你还没有尝试过,这可能会帮助到你:关闭清单文件,然后在Android Studio中执行 文件 -> 使用Gradle文件同步项目。

我在“文件”下没有那个选项... 我的选项是“新建”,“打开...”,“配置文件或调试APK”,“最近打开”,“关闭项目”,“项目结构”,“文件属性”,“本地历史记录”,“全部保存”,“从磁盘重新加载所有”,“无效缓存/重启”,“管理IDE设置”,“新项目设置”,“导出”,“打印”,“添加到收藏夹”和“省电模式”... - CORals
在这种情况下,这可能会有所帮助:https://dev59.com/-FUL5IYBdhLWcg3w8r2D#64119176 - joachimwedin
1
似乎我错过了菜单选项,因为我试图在项目视图中进入菜单。解决方案是首先在项目视图中找到Android清单文件,然后在右上角选择“在Android Studio中打开以进行编辑”。然后菜单选项就可用了,我也可以与Gradle文件同步。 - CORals

-1

感谢@joachimwedin指导我正确的方向。

在build.gradle文件以及文件 ->项目设置 ->模块 ->依赖项“模块SDK”中存在问题,未正确设置。我还在build.gradle中将“GradleException()”更改为“FileNotFoundException()”。详见: https://github.com/flutter/flutter/issues/29608#issuecomment-548649907。 在文件 -> 无效缓存 / 重启后,这暂时删除了所有androidManifest错误 - 但随后它们又回来了。

对我有用的解决方法是将包名称添加到“.MainActivity”的位置。结果是:“'package'.MainActivity”。现在错误已经消失,问题得到解决。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接