我在这里读过类似的问题,但我仍然不清楚一些事情。使用库项目意味着我的整个项目将有两个 list ——一个用于库,另一个用于“主”应用程序项目——我不清楚其中的内容或是否有一些冗余。
我正在开发一个具有“精简版”和“付费”版本的应用小部件,因此几乎所有代码都将包含在库项目中。作为一个小部件,库将至少有一个接收器、一个服务、一个配置 Activity ,以及一些其他 Activity 。那么这些组件的完整声明——包括 Intent 、过滤器等——应该在哪里声明呢?它们是在库的 list 中,还是在应用程序包本身的 list 中,引用库中的类(例如 android:name="com.foo.mylibrary.MyService")?
我看过的一些示例似乎在两个 list 中都声明了它们,但我怀疑将它们放在一个或另一个中是无操作的。
最佳答案
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.
目前未使用库项目 list 。
Gradle for Android 和 Android Studio 支持库项目和发布 list 的 AAR。这可能包括 Activity 声明、所需的权限或功能或最低支持的 Android SDK 级别等内容。
库 list 如何与应用程序自己的 list 合并的规则——特别是当您考虑构建类型和产品风格时——是a bit complex .
So where should the full declarations of these components -- including intents, filters, etc. -- be declared?
在宿主项目中。
该库可以发布这些组件,然后 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")?
后者。
在任何一个中(使用 Gradle for Android 和 Android Studio)。理论上,库更容易发布组件,因此应用程序作者不必这样做。就我个人而言,我不是这方面的忠实拥护者,因为太多的开发人员最终会运送不必要的 list 条目。
关于Android 库 list 与应用 list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10179198/