Android 库清单与应用程序清单 [英] Android Library Manifest vs. App Manifest

查看:32
本文介绍了Android 库清单与应用程序清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里读过类似的问题,但仍然不清楚一些事情.使用库项目意味着我的整个项目将有两个清单——一个用于库,另一个用于主"应用项目——我不清楚其中有哪些内容,或者是否有一些冗余.

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

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

解决方案

使用库项目意味着我的整个项目将有两个清单——一个用于库,另一个用于主"应用项目——我不清楚其中有哪些内容,或者是否有一些冗余.

目前未使用库项目清单.

Android 版 Gradle 以及 Android Studio 支持发布清单的库项目和 AAR.这可能包括活动声明、所需的权限或功能,或者受支持的最低 Android SDK 级别.

关于如何将库清单与应用自己的清单合并的规则——特别是当你考虑构建类型和产品风格时——是 有点复杂.

<块引用>

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

在宿主项目中.

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

<块引用>

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

后者.

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

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")?

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.

解决方案

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.

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.

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")?

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.

这篇关于Android 库清单与应用程序清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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