How to address "Attribute android: ** not allowed here" errors?

1,677

If you haven't tried it already, this might help: close the manifest and then in Android Studio do File -> Sync Project with Gradle Files.

Share:
1,677
CORals
Author by

CORals

Updated on December 31, 2022

Comments

  • CORals
    CORals 10 months

    I came to realize that there are errors in my main/AndroidManifest.xml file. Most of them report: "Atribute android:** not allowed here" (** = icon, launchMode, theme, configChanges, hardwareAccelerated, usesCleartextTraffic and windowSoftInputMode). There is also an error: "Unresolved class '.MainActivity' (see attached screenshot).

    This does not hinder building the app, and publishing it, but some functions are not working.

    I tried to create a new and clean flutter project (counting taps), but got the same errors. I tried to create a new flutter project on a different computer and even on different os (both Windows and Mac) but the problems are still there. And I updated to the newest Android Studio (Arctic Fox 2020.3.1).

    Pub get finished with exit code 0. Pub upgrade finished with exit code 0. Pub outdated finished with exit code 0. Flutter doctor -v reports:

    [✓] 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 https://github.com/flutter/flutter.git • 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 plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-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!

    I have closed and reopened the AndoidManifest file. I have tried File -> Invalidate caches/Restart. I have set File -> Project Structure -> Project Project SDK to "Android API 29 platform". I have built, cleaned and rebuilt the project.

    My AndroidManifest file looks like this:

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

    The error messages look like this:

    Errors - screenshot

    There is no MainActivity.xml file, but there is a MainActivity.kt file placed in app/src/main/kotlin/test_test_test/test_test_test/.

    The code is:

    package com.test_test_test.test_test_test
    
    import io.flutter.embedding.android.FlutterActivity
    
    class MainActivity: FlutterActivity() {
    }
    

    Anyone who can help me out with this issue?

    Kind regards, Christian

  • CORals
    CORals about 2 years
    I don't have that option under File... My options are "New", "Open...", "Profile or Debug APK", "Open Recent", "Close Project", "Project Structure", "File Properties", "Local History", "Save all", "Reload All from Disk", "Invalidate Caches / Restart", "Manage IDE Settings", "New Project Settings", "Export", "Print", "Add to Favorites" and "Power Save Mode"...
  • joachimwedin
    joachimwedin about 2 years
    In that case, this might be helpful: stackoverflow.com/a/64119176/4862855
  • CORals
    CORals about 2 years
    It seems I was missing the menu alternatives because I tried to enter the menu in project view. The solution was first to find the Android Manifest file in project view, then choose "Open for editing in Android Studio" in the top right corner. Then menu alternatives were available and I could also sync with Gradle files.