Manifest merger failed : android:exported needs to be explicitly specified for element <activity#com.example.myapplication.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.
时间: 2024-04-26 19:21:26 浏览: 11
这个问题是因为在Android 12及以上版本中,如果一个Activity有intent filter,就必须显式地指定android:exported属性的值。要解决这个问题,你需要在你的AndroidManifest.xml文件中为MainActivity显式地指定android:exported属性的值。具体步骤如下:
1. 打开AndroidManifest.xml文件,找到MainActivity的声明。
2. 在MainActivity的声明中添加一个android:exported属性,并为其指定一个值。例如,android:exported="true"。
3. 如果你的应用中还有其他具有intent filter的组件(比如Service、BroadcastReceiver等),则需要为它们也指定相应的android:exported属性值。
注意,如果你的应用中的组件不需要被其他应用程序访问,应该将android:exported属性的值设为false,以确保你的应用程序的安全性。
如果你不想在AndroidManifest.xml文件中为每个具有intent filter的组件都显式地指定android:exported属性,你可以在应用的gradle文件中添加以下代码:
```groovy
android {
// ...
compileSdkVersion 31
defaultConfig {
// ...
minSdkVersion 21
targetSdkVersion 31
// ...
}
// Add the following block to your build.gradle file
buildFeatures {
// ...
androidComponents true
// ...
}
}
```
这样做会使用默认值为具有intent filter的所有组件生成android:exported属性值,这些默认值会根据你的应用程序的特定设置进行计算。