清单合并失败:针对Android12的应用程序-AndroidStudio错误
首先,这不是重复的。
我已将模拟器版本和 android SDK 版本更新为 Android S (Android 12) 但更新后。我无法运行该项目。我无法运行 hello world 项目(空项目)。但是我可以构建成绩,但不能运行该项目。我总是收到错误:
***Manifest merger failed: 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.***
请任何人都可以帮助我吗?
这是一个截图...
回答
您需要指定android:exported="false"或android:exported="true"
显现:
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.MyApplication.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
如文件中所述
如果您的应用面向 Android 12 并包含使用 Intent 过滤器的活动、服务或广播接收器,则您必须明确声明这些应用组件的 android: 导出属性。
警告:如果活动、服务或广播接收器使用意图过滤器并且没有明确声明的 android:exported 值,则您的应用无法安装在运行 Android 12 的设备上。
还要检查何时对 'android:exported' 值使用 true/false
回答
在您的清单中,在您的默认启动活动属性中添加android:exported="true"或 android:exported="false "。
完毕!。您可以在Android 12上运行您的应用程序。
<表明...
<activity
android:name=".ui.dashboard.DashboardActivity"
android:screenOrientation="portrait"
android:exported="true"
android:theme="@style/AppTheme.Launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
根据您的要求设置android:exported值。
广播接收器是否可以从其应用程序之外的非系统源接收消息 - 如果可以,则为“true”,否则为“false”。如果为“false”,则广播接收器只能接收由系统、同一应用程序的组件或具有相同用户 ID 的应用程序发送的消息。
如果未指定,默认值取决于广播接收器是否包含意图过滤器。如果接收器包含至少一个意图过滤器,则默认值为“true”。否则,默认值为“false”。
此属性不是限制广播接收器的外部暴露的唯一方法。您还可以使用权限来限制可以发送消息的外部实体(请参阅权限属性)。
来自Android 文档