如何使用新的清单合并(Android的Studio和摇篮)?

如何使用新的清单合并(Android的Studio和摇篮)?

问题描述:

在过去,当Eclipse和放大器; ADT是官方的工具来开发针对Android,你可以简单地使用 manifestmerger.enabled = TRUE 里面的 project.properties 该应用程序的项目>,你得到了它合并所有库清单的自动(我已经张贴了关于它的 这里 )。

In the past, when Eclipse&ADT were the official tools to develop for Android, you could simply use "manifestmerger.enabled=true" inside the "project.properties" of the app's project, and you got it merging all of the libraries' manifests automatically (and I've posted about it here).

这工作,有时。它有很多奇奇怪怪的问题,我总是$ pferred只是避免使用它,并把所需要到主清单文件手动p $。

This worked, sometimes. It had a lot of weird issues, and I always preferred to just avoid using it, and put what is needed into the main manifest file manually.

在某处2014年,谷歌宣布新的Andr​​oid工作室(0.1我认为),连同摇篮,将让你选择究竟是如何执行图书馆的组成部分合并。

Somewhere on 2014, Google announced that the new Android-Studio (0.1 I think), together with Gradle, will allow you to choose exactly how to perform merging of libraries' components.

不过,新指令(链接here)是非常复杂的,我真的(真的),试图了解如何使用他们,也没有找到如何使用它们。样品

However, the new instructions (link here) are very complex and I really (really) tried to understand how to use them, and also didn't find samples of how to use them.

这并不是说我不明白什么,但我不知道如果我的理解很好。

It's not that I didn't understand anything, but I'm not sure if I understood well.

在光明的一面,我发现,合并是完全自动完成的,因此,如果您对图书馆的清单一个BroadcastReceiver(并为一类,当然),它会被添加到应用程序的项目,用途吧。

On the bright side, I've found out that merging is done completely automatically, so if you have a BroadcastReceiver on the library's manifest (and as a class, of course), it will be added to the app's project that uses it.

我不能简单地要求的一切进行解释。我认为这将足以问这些问题:

I can't simply ask everything to be explained. I think it will be enough to ask those questions:

  1. 如何选择哪些应用程序组件(权限,活动,...)将被自动忽略合并?

  1. How can I choose which app components (permissions, activities,...) to be ignored from being auto-merged?

我怎么能点覆盖的应用程序组件(库)的属性(在应用程序的项目)?例如活动的主题?

How can I point override app components (of the library) attributes (on the app's project) ? for example the theme of the activities?

有没有办法完全禁用自动合并的清单文件?

Is there a way to completely disable the auto-merger for the manifest files?

什么有依赖性,其内部存储库清单会发生什么?他们是否合并吗?

What happens with manifests of dependencies that are inside repositories? Are they merged too?

有没有关于这个新的(以及新的对我来说)功能,任何教程/样本/视频?

Are there any tutorials/samples/videos regarding this new (well new for me) feature?

是否有任何事情,我应该知道使用自动合并时?

Are there any things I should be aware of when using the auto-merger?

我希望这些问题被重新presentative不够,信息就够了,但不是太难的,谁知道人的回答。

I hope those questions are representative enough, informative enough, yet not too hard to answer for people who know.

您可以随时明确禁用权限和功能在你的应用程序的清单,并覆盖任何图书馆的值。我发现you可以禁止从图书馆的元素。

1. Disabling elements

You can always explicitly disable permissions and features in your app's manifest and override any library values. And i found that you can disable elements from library.

示例

从上面的链接考虑以下code:

Consider the following code from the above link:

<activity-alias
    android:name="foo.bar.alias">
  <meta-data 
      android:name="zoo" 
      tools:node="remove"/>
</activity-alias>

通过让您的清单这里面code可以确保合并发现任何&LT;以活动为别名&GT; 元素的android:名字=foo.bar.alias属性和删除一个&LT;元数据&GT; 元素,如果它有安卓:NAME =动物园属性。它消除了只动物园的元数据。不活动的别名。如果您在主清单注明这一点,将是任何已经(从库中的元素)合并至今有效。

By having this code inside your manifest you ensure that the merger finds any <activity-alias> elements with android:name="foo.bar.alias" attribute and removes a <meta-data> element if it has the android:name="zoo" attribute. It removes just the "zoo" meta data. Not the activity alias. If you specify this in your main manifest it will be effective on anything that has been merged so far (elements from libraries).

例2

既然你要求与活动的一个例子,这是我想出来的:

Since you requested an example with activities, this is what I've come up with:

<activity android:name="com.example.ui.MyActivity" tools:node="remove"/>

这行将使合并删除与的活动机器人:名称=com.example.ui.MyActivity已合并至今属性。所以,如果你在你的主清单中注明这一点,将有效地消除可能已被合并,从库中的任何 com.example.ui.MyActivity 项。

This line will make the merger remove any activities with android:name="com.example.ui.MyActivity" attribute that have been merged so far. So if you specify this in your main manifest it will effectively remove any com.example.ui.MyActivity entries that might have been merged from libraries.

在这里描述值被合并的顺序一>第Manifest文件排序。基本上它是这样的:图书馆,则主要表现,然后口味和建设型表现,如果你使用这些。 How覆盖从库属性?

什么是生成类型?

默认是调试和释放。您可以定义自己的,并覆盖样设置的签署 ProGuard的的。你的目的,你可以说这是运行配置的相同。

The default are "debug" and "release". You can define your own and override settings like signing or proguard. For your purposes you could say it's the equivalent of run configurations.

它的工作原理是这样的:你把你的默认和共同的价值观里面的清单。然后,在的味道的体现你重写你所需要的值。谷歌摇篮风味的更多信息。

It works like this: you put your default and shared values inside the main manifest. Then in flavor manifests you override the values you need. Google "gradle flavors" for more info.

Disable在Android的摇篮清单合并建立

android.applicationVariants.all { variant ->
    variant.processResources.manifestFile = file('src/main/AndroidManifest.xml')
    variant.processManifest.enabled=false
}

在哪些文件,你把这个?

在年底你的模块的(而不是根项目) build.gradle

At the end of your module's (not root project) build.gradle.

是的,他们是(他们是库)。

Yes they are (they're libraries).

有没有办法来阻止合并的某种的库清单?

Is there a way to block merging certain library manifests?

不,我知道了,对不起。

Not that I know of, sorry.

取决于你有什么才达到。到目前为止,它一直为我工作外的开箱即用的。

Depends on what are you trying to achive. So far it always worked for me out-of-the-box.

  • 即。 http://www.myandroidsolutions.com/2014/04/10/android-gradle-manifest-merge/
  • 在该清单合并文件(下面的链接)。

我不知道任何视频。

您可以检查生成的清单,如果你怀疑额外的权限等,它位于project/module/build/intermediates/manifests/full/[flavor]/build-type/AndroidManifest.xml$c$c>.

You can check the generated manifest if you get suspicious about extra permissions etc. It's located in project/module/build/intermediates/manifests/full/[flavor]/build-type/AndroidManifest.xml.

调料:http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger