Manifest merge failed with multiple errors, see logs in Android Studioo

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

所以,我是 Android 和 Kotlin 的初学者。我刚开始学习。今天在尝试 Intent 时,我遇到了一个错误。

Manifest merger failed with multiple errors, see logs

我在这里找到了一些解决方案并尝试实施它们,但是没有用。

这是我的 build.gradle :

`

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 33

    defaultConfig {
        applicationId "com.example.chattery"
        minSdkVersion 21
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleDependency
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.firebase:firebase-auth:21.1.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.firebase:firebase-database:20.1.0'
    implementation 'com.google.firebase:firebase-storage:20.1.0'
    implementation 'com.google.firebase:firebase-messaging:23.1.0'
    implementation 'com.google.firebase:firebase-auth-ktx:21.1.0'
    implementation 'com.google.firebase:firebase-database-ktx:20.1.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'com.mikhaellopez:circularimageview:4.2.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.firebaseui:firebase-ui-database:4.3.0'
    implementation 'id.zelory:compressor:3.0.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
    implementation 'com.squareup.okhttp:okhttp:2.7.5'
}

`

这是我的 AndroidManifest:

`

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.chattery">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:name=".commons.ChatteryApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".ui.activities.ChatActivity"
            android:theme="@style/ActivityActionBarTheme"
            android:parentActivityName=".ui.activities.MainActivity"/>
        <activity
            android:name=".ui.activities.SettingsActivity"
            android:parentActivityName=".ui.activities.MainActivity" />
        <activity android:name=".ui.activities.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.activities.WelcomeActivity"
            android:screenOrientation="portrait"
            android:theme="@style/LoginTheme" />
        <activity
            android:name=".ui.activities.SignUpActivity"
            android:parentActivityName=".ui.activities.WelcomeActivity"
            android:theme="@style/ActivityActionBarTheme" />
        <activity
            android:name=".ui.activities.LoginActivity"
            android:parentActivityName=".ui.activities.WelcomeActivity"
            android:theme="@style/ActivityActionBarTheme" />
        <activity
            android:name=".ui.activities.UsersActivity"
            android:parentActivityName=".ui.activities.SettingsActivity"
            android:theme="@style/ActivityActionBarTheme" />
        <activity android:name=".ui.activities.ProfileActivity">
            <intent-filter>
                <action android:name="com.example.chattery.NOTIFICATION_TARGET" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
            android:theme="@style/Base.Theme.AppCompat" />

        <service
            android:name=".firebase.MessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
    </application>

</manifest>

`

这是我的合并错误:

Merging Errors: 
Error: android:exported needs to be explicitly specified for element <activity#com.example.chattery.ui.activities.MainActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. Chattery.app main manifest (this file), line 23 Error: android:exported needs to be explicitly specified for element <activity#com.example.chattery.ui.activities.ProfileActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. Chattery.app main manifest (this file), line 46 

这是我编码的第一周,如果这真的很愚蠢,我很抱歉。我对此很陌生,没有找到任何其他地方可以问。对不起,如果我违反了任何规则

android firebase kotlin android-manifest manifest-merging
2个回答
0
投票

错误信息

如错误消息所示,您可能希望将

android:exported
添加到您的活动定义中。它还会告诉您一个事实,即只有 targetSdk >= 31 时才会出现这种情况。因此,另一种解决方案是降低 targetSdk。但这会带来一些功能权衡。我不建议这样做。

方案一(推荐)

根据这个声明here。 Google 建议不要将此属性不必要地设置为

true

所以最简单的解决方案是在您的 AndroidManifest.xml 中更改它:

<activity android:name=".ui.activities.MainActivity">
     <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
</activity>

对此:

<activity android:name=".ui.activities.MainActivity" android:exported="false">
     <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
</activity>

注意添加的

android:exported
属性。

方案二(不推荐)

在您的模块级别

gradle.build
,您在顶部的某个地方有属性
targetSdk
。将值更改为低于
31
例如。
30
对应于
Android 11
。请注意,您需要通过 sdk 管理器下载所需的目标 sdk。否则你将无法再编译你的应用


0
投票

androidTestImplementation 'androidx.test.ext:junit:1.1.3'

© www.soinside.com 2019 - 2024. All rights reserved.