我已经将模拟器版本和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 12后,我也遇到了同样的问题。

问题是这个项目非常大,有多个AndroidManifest.xml文件,而且android:exported在很多地方都不见了。

我最终创建了一个Gradle任务来填补缺失的android:为我自动导出属性。

这里是链接。

其他回答

在我的项目瞄准Android 12后,我也遇到了同样的问题。

问题是这个项目非常大,有多个AndroidManifest.xml文件,而且android:exported在很多地方都不见了。

我最终创建了一个Gradle任务来填补缺失的android:为我自动导出属性。

这里是链接。

在你的启动器活动中,声明"android: exported":

<activity android:name=".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= true”为真,则意味着任何应用程序都可以访问该活动,并且可以通过其确切的类名启动。

如果“android: exported = false”为false,则意味着该活动只能由具有相同用户ID的同一应用程序的组件或特权系统组件启动。

更多详情请点击这里。

更新androidTestImplementation 'androidx.test.ext:junit:1.1.1'到最新版本,如下:

androidtestimplemimplementation ` androidx.test.ext:junit:1.1.3'从构建。Gradle应用级别。

我还必须添加android:exported="true"到我在清单中声明的所有接收器。所以我有这样的东西:

<receiver android:name=".alarms.AlarmReScheduler"
          android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        <action android:name="android.intent.action.PACKAGE_REPLACED" />

        <!-- For HTC devices -->
        <action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
    </intent-filter>
</receiver>

我不认为你应该把android:exported="true"添加到所有东西。你应该只在那些Broadcast接收器需要对Android OS可见时添加它。这段代码中的Intent过滤器意味着我想让Android OS唤醒我的Android应用程序并执行一个操作。

Android .intent.action. boot_completed就是一个很好的例子,因为Android OS会向安装在设备中的每个应用程序发送广播。所以从技术上讲,这意味着任何带有动作的intent过滤器的Broadcast接收器都应该声明android:exported="true"。

在你的清单,添加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" />