针对 Android 12 的清单合并失败

SVP*_*SVP 17 android android-manifest android-studio android-12

使用 Android Studio 4.2.1,在我的 build.gradle 文件中将 sdk 目标更改为 Android 12 后,出现Manifest merger failed with multiple errors, see logs错误。

Merged Manifest选项卡中显示的错误如下:

Merging Errors: 
Error: 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. My_App.app main manifest (this file) 
Error: 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. My_App.app main manifest (this file) 
Error: 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. My_App.app main manifest (this file) 
Run Code Online (Sandbox Code Playgroud)

但是,该android:exported标记已应用在我的 AndroidManifest.xml 文件中。我只有一项活动。没有服务或广播接收器。见下文:

Merging Errors: 
Error: 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. My_App.app main manifest (this file) 
Error: 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. My_App.app main manifest (this file) 
Error: 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. My_App.app main manifest (this file) 
Run Code Online (Sandbox Code Playgroud)

我的 build.gradle(:app) 文件:

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

    defaultConfig {
        ...
        minSdkVersion 23
        targetSdkVersion("S")
        ...
}
Run Code Online (Sandbox Code Playgroud)

知道我如何解决这个问题吗?

SVP*_*SVP 37

该问题是由 3 个活动android:exportedandroidx.test:core库版本中缺少该属性引起的1.3.0。升级到版本1.4.0-beta01解决了这个问题。

如果您在面向 Android 12 后遇到错误,最简单的调试方法是:

  • 降级到之前的 sdk 版本
  • 重建项目
  • 成功构建后,打开项目的AndroidManifest.xml.
  • 在窗口底部,单击Merged Manifest选项卡
  • 查找任何<activity>包含<intent-filter>标签但缺少该android:exported属性的内容

如果您想确保这些活动是问题所在,请将它们直接添加到您的项目AndroidManifest.xml文件中,并android:exported添加缺失的属性,然后尝试重建项目。

因此,如果<activity android:name="com.domain.ProblemActivity">缺少该android:exported属性,请将其添加到您的AndroidManifest.xml文件中,如下所示:

<activity 
 android:name="com.domain.ProblemActivity"
 android:exported="true" >
Run Code Online (Sandbox Code Playgroud)

针对 Android 12 重新构建,如果它有效,那么您就找到了错误!

感谢@MikePenz为我指明了正确的方向。

  • 不在我的项目中工作。我没有使用没有导出属性的意图过滤器的活动,但仍然有这个编译错误!如何找到没有导出属性的活动的确切位置? (5认同)
  • 如果将其添加到 `&lt;activity&gt;` 后仍然失败,您还需要将 `android:exported` 添加到您的 `receiver` /sf/answers/4802353461/ (4认同)
  • 谢谢你的提示。我能够找到缺少导出属性的活动。这确实是来自第三方库的活动,自动添加到清单中。 (2认同)
  • 这些步骤肯定有帮助。我忘记使用导航组件中的“&lt;nav-graph&gt;”也会生成“&lt;intent-filter&gt;”标签。您还需要将导出的属性添加到这些活动中。 (2认同)
  • 通过运行 `gradlew processDebugAndroidTestManifest --debug` 并向上滚动到显示“面向 Android 12 及更高版本的应用程序...”文本的位置,我能够找出导致我的项目出现问题的原因。在我的例子中,上面的 INFO 行显示了需要更新到 3.4.0 的合并浓缩咖啡。另一个需要更新的是 WorkManager。 (2认同)
  • 我在尝试在(组合中的导航/测试)代码实验室期间运行测试时遇到了此问题。正如@Blake所说,我运行了“./gradlew processDebugAndroidTestManifest --debug”。对我来说,它是 **espresso-contrib** 和 **espresso-core**。按**`ctrl+alt+shift+s`**,选择*依赖项*,然后选择最高可用版本(当时为*3.5.0-alpha03*),在执行以下操作后解决了问题与*应用*和*确定*。 (2认同)

Mar*_*DSC 9

如果您的应用以 Android 12 或更高版本为目标平台,并且包含使用 Intent 过滤器的活动、服务或广播接收器,则必须为这些应用组件显式声明 android:exported 属性。为了解决这个问题,我们需要执行以下步骤:

  1. 我们需要在主文件夹中找到 AndroidManifest.xml。

android>app>src>main>AndroidManifest.xml

在此输入图像描述

  1. 我们必须android:exported=""在这些引号内添加并设置一个布尔值。现在您可能会问我什么时候需要添加android:exported="true"android:exported="false"添加到使用意图过滤器的活动、服务或广播接收器。如果应用程序组件包含 LAUNCHER 类别,请将 android:exported 设置为 true。在大多数其他情况下,将 android:exported 设置为 false。

  2. 这是 AndroidManifest.xml 中的示例

<service android:name="com.example.app.backgroundService"
         android:exported="false">
    <intent-filter>
        <action android:name="com.example.app.START_BACKGROUND" />
    </intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)

您可以通过以下链接查看有关此主题的更多信息:

Android 12 更安全的组件导出


小智 6

如果您将 Android Studio 升级到 Bumblebee 2021.1.1。需要进行以下更改: 步骤 1:您targetSdkVersion必须年满 30 岁或更高 步骤 2:将您的appcompat库更新为implementation 'androidx.appcompat:appcompat:1.4.1'

步骤 3:在 AndroidManifest 文件中添加android:exported = true到您的 Activity 启动器。


归档时间:

查看次数:

5839 次

最近记录:

4 年,4 月 前