Android升级targetSdk到31时如何覆盖三方库的android:exported属性?
解决方案
- 第一步:在你app主模块的
AndroidManifest.xml根<manifest>标签中添加tools命名空间声明:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="你的应用包名">
- 第二步:在该Manifest的
<application>标签内,手动声明三方库的这个Service,同时添加tools:replace="android:exported"属性指定覆盖原有配置:
<application ......> <!-- 覆盖三方库的MessagingService配置 --> <service android:name="com.****.MessagingService" android:exported="false" tools:replace="android:exported"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> ...... 你的其他组件声明 </application>
注意事项
android:name属性的值必须和三方库中声明的Service全类名完全一致,否则无法匹配到对应组件完成覆盖- 编译完成后可以查看合并后的Manifest文件,确认
android:exported属性是否已经按照你的配置生效
内容的提问来源于stack exchange,提问作者yusufonderd
相关产品推荐
相关产品推荐

