我已经将模拟器版本和Android SDK版本更新到Android S (Android 12)。更新后,我无法运行项目。我不能运行Hello, World!项目(空项目),但我可以建立Gradle以及,但我不能运行项目。我总是得到错误:

Manifest合并失败:针对Android 12及更高版本的应用程序失败 需要为android指定一个显式值:当 相应的组件定义了一个意图过滤器。看到 https://developer.android.com/guide/topics/manifest/activity-element#exported 获取详细信息。

我该怎么解决呢?

以下是截图:

使用Android 12 SDK时如何解决此问题?

这个问题是应用这个问题的解决方案之后的问题,和这个问题不一样。而且,这个问题比这个更古老。


当前回答

在你的清单,添加android:exported="true"或android:exported="false "在你的默认启动活动属性。

完成了!你可以在Android 12上运行你的应用程序。

<manifest ... >

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

根据需要设置“android:exported”的值。

广播接收器是否可以从其应用程序之外的非系统源接收消息——如果可以,则为"true",如果不能,则为"false"。如果“false”,广播接收器只能接收由系统、相同应用程序的组件或具有相同用户ID的应用程序发送的消息。

如果未指定,默认值取决于广播接收器是否包含意图过滤器。如果接收端包含至少一个意图过滤器,则默认值为“true”。否则,默认值为false。

此属性不是限制广播接收器外部曝光的唯一方法。您还可以使用权限限制可以发送消息的外部实体(请参阅permission属性)。

来自Android文档

其他回答

针对Android 12的应用

将应用程序的targetSdkVersion更改为S(32或31)以启用新行为。

然后将Manifest中的android:exported=""属性指定为true或false,具体取决于Activity。

对于启动器活动,如splash或MainActivity,使用android:exported="true",对于其余的活动,使用android:exported="false"

例如:

<!-- It's **true** for the launcher Activity -->
<activity android:name=".SplashActivity"
          android:exported="true" />

<!-- It's **false** for the rest of the Activities -->
<activity android:name=".MainActivity"
          android:exported="false" />

你需要指定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,并包含活动,服务,或 广播接收器使用意图过滤器,你必须显式 为这些应用组件声明android: exported属性。

警告:如果活动、服务或广播接收器使用intent 的过滤器,并且没有显式声明的值 Android:导出,您的应用程序不能安装在运行的设备上 Android 12。

还要检查何时为'android:exported'值使用true/false。

你的问题可能被标记为重复,因为这篇文章:针对Android 12的Manifest合并失败,尽管你的文章是在一周前发布的。我现在看不到国旗了。

为了澄清另一个答案,请注意,android:exported应该为你的主活动设置为true,否则它将不会启动,尽管android Studio有鼓励的“启动成功”消息,因为没有其他应用程序,甚至android系统本身,可以启动它。

<activity
    android:name=".MainActivity"
    android:exported="true"

对于其他意图隐藏在合并清单中的活动,这通常会被设置为false。

我得到这个错误,甚至当我添加android: exports =“true”在所有活动,接收器等。对我有用的是将compileSdkVersion和targetSdkVersion更改为30。

在你的清单,添加android:exported="true"或android:exported="false "在你的默认启动活动属性。

完成了!你可以在Android 12上运行你的应用程序。

启动器活动所需

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

接收方要求

<receiver android:name=".Musicreceiver"
          android:exported="true">

</receiver>

服务要求


    <service
        android:name=".service.LoggerService"
        android:exported="true"
        android:enabled="true" />