错误:覆盖清单:在 AndroidManifest.xml:2:5-34 中声明的包属性。颤动

问题描述 投票:0回答:5

简单的问题, 很难解决(我认为),

当我启动 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.

这是我的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
    }

这是我的 AndroidManifest.xml:

package="com.example.Scanner">

我希望有人可以帮助我,否则我无法再在这个应用程序上编程了:(

删除

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

android flutter android-manifest
5个回答
22
投票

我也遇到了同样的问题,我更改了 5 个位置的包名称。

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

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

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

  4. buildgradle 文件

    defaultConfig { applicationId ""}

  5. “包”上的 MainActivity.java 或 MainActivity.kotlin

修改上述文件后,Flutter App运行没有任何问题。


7
投票

我也遇到了同样的问题,但经过以下步骤后我明白了我的意思;

您的包名称“com.example.com”(在您的情况下可能不同)在 5 个位置应该相同,例如

1.

android/app/src/debug/AndroidManifest.xml

2.

android/app/src/main/AndroidManifest.xml

3.

android/app/src/profile/AdroidManifest.xml

4.

buildgradle
文件
defaultConfig { applicationId ""}

5.

MainActivity.java
“包装”上或
MainActivity.kotlin

就我而言,我的包名称是 com.example.blog_daily。所以我在所有点上重写了所有同名的包并解决了我的问题。


4
投票

Midhun MP 的工作 [https://stackoverflow.com/users/1104384/midhun-mp]:

从 androidmanifest 中删除 package 属性并检查

我犯了一个错误。然后我得到了一个新的java错误。我只将 AndroidManifest.xml 从旧项目复制到新项目,并且它有效。这对我有用:

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

,但我不知道出了什么问题。我从来没有改变过。 只要改变

package="com.example.YOURNAME">
android:label="YOURNAME"


2
投票

首先使所有包名称相同//要在终端中显示的搜索栏中搜索您的包名称并修复它们// 然后运行 flutter clean 和 flutter pub get。 现在你可以运行 flutter run 。我想这会解决你的问题。


0
投票
I just changed my androidmanifest package name to my project level build.gradle's application id that worked to me. 

//
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="-pasted here-`enter code here`"

from
//
defaultConfig {
        // TOD: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "-copied from here-"
        minSdkVersion`enter code here` 24
        targetSdkVersion 33
© www.soinside.com 2019 - 2024. All rights reserved.