简体   繁体   中英

Error: Overlay manifest:package atribute declared at AndroidManifest.xml:2:5-34. Flutter

Simple Proplem, hard to solve (i think),

I get this error when i start my main.dart:

Error:
    Overlay manifest:package attribute declared at AndroidManifest.xml:2:5-34 value=(com.example.Scanner)
    has a different value=(com.example.Scanner) declared in main manifest at AndroidManifest.xml:1:70-97
    Suggestion: remove the overlay declaration at AndroidManifest.xml   and place it in the build.gradle:
        flavorName {
            applicationId = "com.example.Scanner"
        }

FAILURE: Build failed with an exception.

This is my build.gradle:

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId="com.example.Scanner"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

and this is my AndroidManifest.xml:

package="com.example.Scanner">

I hope someone can help me, otherwise i can´t program at this app anymore:(

After removing package="com.example.Scanner" i get this error:

Launching lib\main.dart on PCT L29 in debug mode...
lib\main.dart:1
√ Built build\app\outputs\flutter-apk\app-debug.apk.
E/AndroidRuntime(18958): FATAL EXCEPTION: main
E/AndroidRuntime(18958): Process: com.example.Scanner, PID: 18958
E/AndroidRuntime(18958): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.Scanner/your_package_name.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "your_package_name.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.Scanner-qq9H2h8k4abCggEZ2-z28Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.Scanner-qq9H2h8k4abCggEZ2-z28Q==/lib/arm64, /data/app/com.example.Scanner-qq9H2h8k4abCggEZ2-z28Q==/base.apk!/lib/arm64-v8a, /system/lib64, /hw_product/lib64, /system/product/lib64, /prets/lib64]]
E/AndroidRuntime(18958):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3813)
E/AndroidRuntime(18958):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4074)
E/AndroidRuntime(18958):    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
E/AndroidRuntime(18958):    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
E/AndroidRuntime(18958):    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
E/AndroidRuntime(18958):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
E/AndroidRuntime(18958):    at android.os.Handler.dispatchMessage(Handler.java:110)
E/AndroidRuntime(18958):    at android.os.Looper.loop(Looper.java:219)
E/AndroidRuntime(18958):    at android.app.ActivityThread.main(ActivityThread.java:8347)
E/AndroidRuntime(18958):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(18958):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
E/AndroidRuntime(18958):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
E/AndroidRuntime(18958): Caused by: java.lang.ClassNotFoundException: Didn't find class "your_package_name.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.Scanner-qq9H2h8k4abCggEZ2-z28Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.Scanner-qq9H2h8k4abCggEZ2-z28Q==/lib/arm64, /data/app/com.example.Scanner-qq9H2h8k4abCggEZ2-z28Q==/base.apk!/lib/arm64-v8a, /system/lib64, /hw_product/lib64, /system/product/lib64, /prets/lib64]]
E/AndroidRuntime(18958):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:209)
E/AndroidRuntime(18958):    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(18958):    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(18958):    at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
E/AndroidRuntime(18958):    at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:41)
E/AndroidRuntime(18958):    at android.app.Instrumentation.newActivity(Instrumentation.java:1264)
E/AndroidRuntime(18958):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3798)
E/AndroidRuntime(18958):    ... 11 more

With the work from Midhun MP [https://stackoverflow.com/users/1104384/midhun-mp]:

Remove the package attribute from androidmanifest and check

i got one error done. Then i got a new java error. I only copied a AndroidManifest.xml from an old project to a new and it worked. This worked for me:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.Scanner">
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="Scanner"
        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>

, but i have no idea what was wrong. I never changed it or so. Just change package="com.example.YOURNAME"> and android:label="YOURNAME"

I also had the same issue but after going through the following steps I got my point;

Your package name "com.example.com"(in your case It could be different) should be same in 5 locations, like eg

1. android/app/src/debug/AndroidManifest.xml

2. android/app/src/main/AndroidManifest.xml

3. android/app/src/profile/AdroidManifest.xml

4. buildgradle file defaultConfig { applicationId ""}

5. MainActivity.java on "package" OR MainActivity.kotlin

In my case my package name was com.example.blog_daily. So I rewrite all the packages with the same name at all the points and solved my issue.

first make all package name same //to do this search your package name in search bar that show in terminal and fixed them// then run flutter clean and flutter pub get. now you can run flutter run. I think it will solve your problem.

这显示了存储的 3 个 Android 文件 - Android Manifest Files

Hello,

I had the same issue, and I changed the package name in 5 location.

1.) android/app/src/debug/AndroidManifest.xml

2.) android/app/src/main/AndroidManifest.xml

3.) android/app/src/profile/AdroidManifest.xml

4.) buildgradle file defaultConfig { applicationId ""}

5.) MainActivity.java on "package" OR MainActivity.kotlin

After modifying the above files, the Flutter App run without any issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM