Android库Manifest与App Manifest

时间:2021-07-23 15:23:11

I've read similar questions here, but am still not clear on a couple of things. Using a Library Project means that my overall project will have two manifests -- one for the library and the other for the "main" app project -- and I'm not clear what goes in which or if there is some redundancy.

我在这里已经阅读了类似的问题,但我仍然不清楚几件事情。使用库项目意味着我的整个项目将有两个清单 - 一个用于库,另一个用于“主”应用程序项目 - 我不清楚是什么或哪些有冗余。

I'm developing an app widget with "lite" and "paid" versions, so will have almost all code in a library project. Being a widget, the library will have at least a receiver, a service, a configuration activity, plus a couple of other activities. So where should the full declarations of these components -- including intents, filters, etc. -- be declared? Do they go in the manifest for the library, or in the manifest for the application package itself, referencing the classes in the library (e.g. android:name="com.foo.mylibrary.MyService")?

我正在开发一个带有“精简”版本和“付费”版本的应用程序小部件,因此几乎所有代码都在库项目中。作为一个小部件,该库至少会有一个接收器,一个服务,一个配置活动,以及其他一些活动。那么应该在哪里声明这些组件的完整声明 - 包括意图,过滤器等?它们是否在库的清单中,或者在应用程序包本身的清单中,引用库中的类(例如android:name =“com.foo.mylibrary.MyService”)?

Some examples I've looked at seem to declare them in both manifests, but I suspect that putting these in one or the other is a no-op.

我看过的一些例子似乎在两个清单中都声明了它们,但我怀疑将它们放在一个或另一个中是无操作的。

3 个解决方案

#1


43  

Using a Library Project means that my overall project will have two manifests -- one for the library and the other for the "main" app project -- and I'm not clear what goes in which or if there is some redundancy.

使用库项目意味着我的整个项目将有两个清单 - 一个用于库,另一个用于“主”应用程序项目 - 我不清楚是什么或哪些有冗余。

The library project manifest is not presently used.

目前尚未使用库项目清单。

Gradle for Android, and therefore Android Studio, support library projects and AARs publishing a manifest. This can include things like activity declarations, required permissions or features, or minimum supported Android SDK levels.

Gradle for Android,因此Android Studio,支持库项目和AAR发布清单。这可以包括活动声明,所需权限或功能或最低支持的Android SDK级别等内容。

The rules for how library manifests are merged with the app's own manifest -- particularly when you take build types and product flavors into account -- is a bit complex.

库清单如何与应用程序自己的清单合并的规则 - 特别是考虑到构建类型和产品风格时 - 有点复杂。

So where should the full declarations of these components -- including intents, filters, etc. -- be declared?

那么应该在哪里声明这些组件的完整声明 - 包括意图,过滤器等?

In the host project.

在主机项目中。

The library could publish those components, and the Android Studio host project can then remove them if needed.

库可以发布这些组件,然后Android Studio主机项目可以根据需要删除它们。

Do they go in the manifest for the library, or in the manifest for the application package itself, referencing the classes in the library (e.g. android:name="com.foo.mylibrary.MyService")?

它们是否在库的清单中,或者在应用程序包本身的清单中,引用库中的类(例如android:name =“com.foo.mylibrary.MyService”)?

The latter.

后者。

In either (with Gradle for Android and Android Studio). In theory, it is easier for the library to publish the components, so the app author does not have to. Personally, I am not a huge fan of this, as too many developers will wind up shipping unnecessary manifest entries.

在(使用Gradle for Android和Android Studio)中。理论上,库更容易发布组件,因此应用程序作者不必这样做。就个人而言,我并不是这方面的忠实粉丝,因为太多开发人员最终会收集不必要的清单条目。

#2


9  

As of ADT r20 Preview 3 it is now possible to merge manifests. So common configuration can now be put into the library manifest. See https://*.com/a/10400355/262789 for more information.

从ADT r20 Preview 3开始,现在可以合并清单。因此,现在可以将常见配置放入库清单中。有关更多信息,请参阅https://*.com/a/10400355/262789。

Version 13 of Intellij IDEA is necessary for manifest merging support (manifestmerger.enabled=true). Also the Grade based build system appears to be necessary for Android Studio support.

Intellij IDEA的第13版对于清单合并支持是必需的(manifestmerger.enabled = true)。此外,基于成绩的构建系统似乎是Android Studio支持所必需的。

#3


5  

Any referenced android elements like activities, receivers, services, etc. MUST go into your Application manifest or they won't be recognized by the OS. As you guessed, the Library manifest file is pretty much an empty implementation

任何引用的android元素,如活动,接收器,服务等,必须进入你的应用程序清单,否则操作系统将无法识别它们。正如您所猜测的,库清单文件几乎是一个空实现

UPDATE

UPDATE

As CommonsWare points out above, the Android build tools will now attempt to merge the various manifests on your behalf. Leaving up the original answer for posterity

正如CommonsWare上面指出的那样,Android构建工具现在将尝试代表您合并各种清单。为后代留下原始答案

#1


43  

Using a Library Project means that my overall project will have two manifests -- one for the library and the other for the "main" app project -- and I'm not clear what goes in which or if there is some redundancy.

使用库项目意味着我的整个项目将有两个清单 - 一个用于库,另一个用于“主”应用程序项目 - 我不清楚是什么或哪些有冗余。

The library project manifest is not presently used.

目前尚未使用库项目清单。

Gradle for Android, and therefore Android Studio, support library projects and AARs publishing a manifest. This can include things like activity declarations, required permissions or features, or minimum supported Android SDK levels.

Gradle for Android,因此Android Studio,支持库项目和AAR发布清单。这可以包括活动声明,所需权限或功能或最低支持的Android SDK级别等内容。

The rules for how library manifests are merged with the app's own manifest -- particularly when you take build types and product flavors into account -- is a bit complex.

库清单如何与应用程序自己的清单合并的规则 - 特别是考虑到构建类型和产品风格时 - 有点复杂。

So where should the full declarations of these components -- including intents, filters, etc. -- be declared?

那么应该在哪里声明这些组件的完整声明 - 包括意图,过滤器等?

In the host project.

在主机项目中。

The library could publish those components, and the Android Studio host project can then remove them if needed.

库可以发布这些组件,然后Android Studio主机项目可以根据需要删除它们。

Do they go in the manifest for the library, or in the manifest for the application package itself, referencing the classes in the library (e.g. android:name="com.foo.mylibrary.MyService")?

它们是否在库的清单中,或者在应用程序包本身的清单中,引用库中的类(例如android:name =“com.foo.mylibrary.MyService”)?

The latter.

后者。

In either (with Gradle for Android and Android Studio). In theory, it is easier for the library to publish the components, so the app author does not have to. Personally, I am not a huge fan of this, as too many developers will wind up shipping unnecessary manifest entries.

在(使用Gradle for Android和Android Studio)中。理论上,库更容易发布组件,因此应用程序作者不必这样做。就个人而言,我并不是这方面的忠实粉丝,因为太多开发人员最终会收集不必要的清单条目。

#2


9  

As of ADT r20 Preview 3 it is now possible to merge manifests. So common configuration can now be put into the library manifest. See https://*.com/a/10400355/262789 for more information.

从ADT r20 Preview 3开始,现在可以合并清单。因此,现在可以将常见配置放入库清单中。有关更多信息,请参阅https://*.com/a/10400355/262789。

Version 13 of Intellij IDEA is necessary for manifest merging support (manifestmerger.enabled=true). Also the Grade based build system appears to be necessary for Android Studio support.

Intellij IDEA的第13版对于清单合并支持是必需的(manifestmerger.enabled = true)。此外,基于成绩的构建系统似乎是Android Studio支持所必需的。

#3


5  

Any referenced android elements like activities, receivers, services, etc. MUST go into your Application manifest or they won't be recognized by the OS. As you guessed, the Library manifest file is pretty much an empty implementation

任何引用的android元素,如活动,接收器,服务等,必须进入你的应用程序清单,否则操作系统将无法识别它们。正如您所猜测的,库清单文件几乎是一个空实现

UPDATE

UPDATE

As CommonsWare points out above, the Android build tools will now attempt to merge the various manifests on your behalf. Leaving up the original answer for posterity

正如CommonsWare上面指出的那样,Android构建工具现在将尝试代表您合并各种清单。为后代留下原始答案