Gradle 将包装器/子模块的 Android 清单合并到主模块的清单中 [英] Gradle merge wrapper/sub-module's Android manifest into a main module's manifest

查看:23
本文介绍了Gradle 将包装器/子模块的 Android 清单合并到主模块的清单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有以下模块,我无法让 Gradle 正确合并 Android 清单:

I have the following modules inside my project for which I cannot get Gradle to merge the Android manifests properly:

myproject_alpha
myproject_beta
myproject_lib
myproject_release

*_lib 模块是包含所有源代码的项目的主要模块.其他 3 个模块是包装器模块",它们对内容提供者的权限"参数进行了轻微修改,更改了 *_lib 模块清单中指定的活动意图过滤器内的数据"字段,并启用了一些其他活动myproject_release 模块.

The *_lib module is the main module for the project that contains all source code. The other 3 modules are "wrapper modules" that make slight modifications to the content providers' "authorities" parameter, change the "data" field inside an activity's intent filter specified in the *_lib module's manifest, plus enable some other activities not present in myproject_release module.

目前,我有 gradle Android manifest 合并 alpha(或 beta 或 release)与 lib 之间的错误.例如,在 lib 和 alpha 之间,我看到以下 2 个 gradle 错误:

Currently, I have gradle Android manifest merging errors between alpha (or beta or release) vs lib. For example, between lib and alpha I see the following 2 gradle errors:

Trying to merge incompatible /manifest/application/provider[@name=com.myproject.contentprovider.MyProvider] element:
  <provider
--    @android:authorities="com.myproject.alpha.provider"
  <provider
++    @android:authorities="com.myproject.lib.provider"

:myproject_alpha:processDebugManifest FAILED

Trying to merge incompatible /manifest/application/activity[@name=com.myproject.activity.LoginActivity] element:
  <activity
  @android:name="com.myproject.activity.LoginActivity"
          @android:name="android.intent.action.MAIN">
          @android:name="android.intent.category.LAUNCHER">
  <intent-filter>
          @android:name="android.intent.action.VIEW">
          @android:name="android.intent.category.BROWSABLE">
          @android:name="android.intent.category.DEFAULT">
      <data
--            @android:host="myhost.test.com"
  <activity
  @android:name="com.myproject.LoginActivity"
          @android:name="android.intent.action.MAIN">
          @android:name="android.intent.category.LAUNCHER">
  <intent-filter>
          @android:name="android.intent.action.VIEW">
          @android:name="android.intent.category.BROWSABLE">
          @android:name="android.intent.category.DEFAULT">
      <data
++            @android:host="myhost.com"

:myproject_alpha:processDebugManifest FAILED

我发现的唯一类似问题是
Gradle:如何合并 Android 清单文件对于需要相同活动但具有不同意图过滤器的不同构建类型.但是,它并不真正符合我的问题,因为在我的情况下,lib"和alpha"是相互依赖的模块,而不是不同的构建.我会感谢一些反馈.

The only similar question I found was
Gradle: How to merge Android manifest files for different buildTypes which need the same Activity, but with different intent-filters. However, it doesn't really match my issue because in my case "lib" and "alpha" are interdependent modules not different builds. I'll appreciate some feedback.

推荐答案

如果您检查 合并清单的类,你会看到mergeNewOrEqual() 方法不够聪明,无法合并不相同的元素.不幸的是,这是用于合并提供者和活动的方法.

If you examine the class that merges the manifests, you'll see that the mergeNewOrEqual() method is not smart enough to merge elements that are not identical. Unfortunately, this is the method that is used to merge providers and activities.

所以唯一的解决方案"是要么只在一个地方定义元素,要么在两个定义中给它们相同的签名.

So the only "solution" would be to either to only define the elements in one place, or to give them identical signatures in both definitions.

这篇关于Gradle 将包装器/子模块的 Android 清单合并到主模块的清单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆