我已经将模拟器版本和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:出口= " true ":

<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions"/>
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher"/>
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver"
     android:exported="true">

        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
        </intent-filter>
    </receiver>

其他回答

你需要指定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: exported = false”标签的活动,那么它很可能是在你的依赖项中…为了精确定位,首先将“compileSdkVersion”降级为30,将“targetSdkVersion”降级为30,这样它就可以构建了。

android {
    compileSdkVersion("android-S")
    buildToolsVersion "30.0.3"

    defaultConfig {
        ...
        minSdkVersion 23
        targetSdkVersion("S")
        ...
}

之后,在主manifest.xml窗口中有一个带有“merged manifest”的选项卡。在那里,你可以检查哪些活动没有“android: exported = false”属性。

在我的案例中,这是因为第三方工具:

文件建立。Gradle (: app):

debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
//and
debugImplementation "com.github.markzhai:blockcanary-android:1.5.0"
releaseImplementation "com.github.markzhai:blockcanary-no-op:1.5.0"

此外,对于服务,我必须添加属性:

<service
    android:name=".autofillservice.MyAutofillService"
    android:exported="true"
    android:permission="android.permission.BIND_AUTOFILL">

and

<service
    android:name="com.demo.myApp.my_access.MyAccessService"
    android:enabled="true"
    android:exported="true"
    android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">

由于我的问题是在第三方依赖,它不会很快更新,我只是添加了一个<活动>声明与标志android:exported="true"和export ="false"需要覆盖初始声明的地方,也因为我需要这个依赖在调试中,我只添加了一个新的AndroidManifest.xml文件在src/ Debug:

leak_canary:

<?xml version="1.0" encoding="UTF-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <application>
        <activity
            android:name="leakcanary.internal.activity.LeakActivity"
            android:exported="true"
            android:icon="@mipmap/leak_canary_icon"
            android:label="@string/leak_canary_display_activity_label"
            android:taskAffinity="com.squareup.leakcanary.${applicationId}"
            android:theme="@style/leak_canary_LeakCanary.Base">

            <intent-filter android:label="@string/leak_canary_import_hprof_file">

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="file" />
                <data android:scheme="content" />
                <data android:mimeType="*/*" />
                <data android:host="*" />

                <data android:pathPattern=".*\\.hprof" />
                <data android:pathPattern=".*\\..*\\.hprof" />
                <data android:pathPattern=".*\\..*\\..*\\.hprof" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\.hprof" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.hprof" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.hprof" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.hprof" />
            </intent-filter>
        </activity>

        <activity
            android:name="leakcanary.internal.RequestStoragePermissionActivity"
            android:excludeFromRecents="true"
            android:exported="false"
            android:icon="@mipmap/leak_canary_icon"
            android:label="@string/leak_canary_storage_permission_activity_label"
            android:taskAffinity="com.squareup.leakcanary.${applicationId}"
            android:theme="@style/leak_canary_Theme.Transparent" />

        <receiver
            android:name="leakcanary.internal.NotificationReceiver"
            android:exported="false" />

    </application>
</manifest>

你不妨只是使用tools:node="merge"属性,并声明android:exported=true|false作为LeoFarage善意的建议。

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

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

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

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

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

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

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