简体   繁体   English

错误:覆盖清单:package 在 AndroidManifest.xml:2:5-34 声明的属性。 Flutter

[英]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:当我启动 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:这是我的 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:这是我的 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:删除package="com.example.Scanner"后出现此错误:

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]: Midhun MP [https://stackoverflow.com/users/1104384/midhun-mp] 的工作:

Remove the package attribute from androidmanifest and check从 androidmanifest 中删除 package 属性并检查

i got one error done.我完成了一个错误。 Then i got a new java error.然后我得到一个新的 java 错误。 I only copied a AndroidManifest.xml from an old project to a new and it worked.我只将 AndroidManifest.xml 从旧项目复制到新项目,并且它有效。 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"只需更改package="com.example.YOURNAME">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您的 package 名称“com.example.com”(在您的情况下可能不同)在 5 个位置应该相同,例如

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

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

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

4. buildgradle file defaultConfig { applicationId ""} 4. buildgradle文件defaultConfig { applicationId ""}

5. MainActivity.java on "package" OR MainActivity.kotlin 5.“包”上的MainActivity.javaMainActivity.kotlin

In my case my package name was com.example.blog_daily.在我的例子中,我的 package 名称是 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.首先使所有 package 名称相同//要执行此操作,在终端中显示的搜索栏中搜索您的 package 名称并修复它们//然后运行 Z5ACEBC4CB70DDBB074B0AC76AAB176AEDDBB07ZBAC76CB701DDAE7ZBAC76CB701 now you can run flutter run.现在您可以运行 flutter 运行。 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.我遇到了同样的问题,我在 5 个位置更改了 package 名称。

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

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

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

4.) buildgradle file defaultConfig { applicationId ""} 4.) buildgradle 文件 defaultConfig { applicationId ""}

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

After modifying the above files, the Flutter App run without any issues.修改上述文件后,Flutter App运行没有任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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