【问题标题】:Android How can i override exported tag in manifest?Android 如何覆盖清单中的导出标签?
【发布时间】:2021-12-23 18:34:23
【问题描述】:

我想将目标 sdk 从 30 升级到 31。但我得到了那个错误:

清单合并失败:android:exported 需要明确 指定为 .面向 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>

所以这是我的问题。我怎样才能像下面这样将这个服务覆盖为导出的错误?

<service android:exported="false"
 android:name="com.****.MessagingService" >
                <intent-filter>
                    <action android:name="com.google.firebase.MESSAGING_EVENT" />
                </intent-filter>
            </service> 

【问题讨论】:

    标签: android gradle manifest


    【解决方案1】:

    Android Studio 将合并您项目的所有清单文件及其依赖项。

    上层清单总是可以优先考虑并覆盖依赖项中的值。检查这个paragraph in the documentation

    由于依赖项根本没有指定 exported 值,您可以像这样覆盖顶级清单文件中的每个服务:

    <service android:exported="false"
     android:name="com.****.MessagingService" />
    

    这将合并com.****.MessagingService 的服务标签值并应用导出的值。

    【讨论】:

      【解决方案2】:

      你可以替换整个节点

              <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"/>
      

      您可以找到有关此主题的更多信息here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-07-24
        • 2017-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多