我想将目标 sdk 从 30 升级到 31。但是我收到那个错误:
清单合并失败:android:导出需要显式 为 指定。面向 Android 12 及更高版本的应用是 需要为
android:exported
指定显式值,当 相应的组件定义了目的过滤器。看 https://developer.android.com/guide/topics/manifest/activity-element#exported 了解详情。
当我在清单合并中环顾四周时。我看到我在应用程序中使用的第三方库之一没有添加android:exported
标签。
<service android:name="com.****.MessagingService" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
所以这是我的问题。如何将此服务覆盖为导出的 false,如下所示?
<service android:exported="false"
android:name="com.****.MessagingService" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Android Studio 将合并项目的所有清单文件及其依赖项。
上层清单始终可以优先处理并覆盖依赖项中的值。检查文档中的此段落。
由于依赖项根本不指定exported
值,因此可以覆盖顶级清单文件中的每个服务,如下所示:
<service android:exported="false"
android:name="com.****.MessagingService" />
这将合并com.****.MessagingService
的服务标记的值并应用导出的值。
您可以替换整个节点
<service
tools:node="replace"
android:name=".MessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
或者只是您需要替换的属性
<service
tools:replace="exported"
android:name=".MessagingService"
android:exported="false"/>
您可以在此处找到有关此主题的更多信息