Manifest merger failed with multiple errors, see logs in And



所以,我是一个初学者进入Android和Kotlin。我刚开始学习。当我今天在尝试使用Intent时,我出现了一个错误。

Manifest merger failed with multiple errors, see logs

我在这里找到了一些解决方案,并试图实现它们,但它不起作用。

这是我的构建。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:exported添加到活动定义中。它还告诉您这样一个事实,即只有targetSdk>= 31才会出现这种情况。所以另一个解决方案是降低你的目标。但这将带来一些功能上的折衷。我不建议那样做。

解决方案1(推荐)

根据这里的语句。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属性。

解决方案2(不推荐)

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

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

最新更新