Expose an “Android Library Project”'s included jars to Projects which reference them

谁说我不能喝 提交于 2019-12-07 19:18:46

问题


One of the newer functions of Android is the ability to create a Library Project.

This is great for unit testing and sharing common functionality across many apps you may be developing, but I seem to have stumbled upon a bug in their implementation.

When you have the following situation:

-LibraryProject contains LibraryProject/libs/folder/lib.jar in it's build path.

-ReferencingProject references LibraryProject.

From ReferencingProject you don't have access to anything inside lib.jar (Such as constant's used to communicate with methods in the Library Project).

A solution to this is to include "lib.jar" as an external library in the referencing project but this approach begins to negate the benefits you gain from having a self contained Library Project by creating multiple manually added references to resources which could move/change during the development of the library project (not to mention cause some pretty confusing errors).

Is there any way to expose an included libs classes to the referencing project without having to manually reference them as external jars?


回答1:


As @Selvin says,

In the Library Project you can specify which libraries you want to mark as "exported" in the window brought up by using: Project properties => Java Build Path => Order and Export. From this example you would check libs/folder/lib.jar.

Clean and build the Library Project and the "exported" libraries are now included in the produced jar.

EDIT

This is a symptom of upgrading to ADT 17 - (Android Team: Perhaps put a few warnings on your release notes when an update breaks existing architectures?)

http://tools.android.com/recent/dealingwithdependenciesinandroidprojects

If you don't want to add the library to the "Order and Export" then placing local jar's in /libs/ base folder will automatically add it to "Android Dependencies" which are exported in the jar created from your shared library.

EDIT2

Recent ADT upgrade would have you also manually select "Android Dependencies" as "Exported" in your Java Build Path. Again, warning would be nice.



来源:https://stackoverflow.com/questions/10108252/expose-an-android-library-projects-included-jars-to-projects-which-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!