Expose an “Android Library Project”'s included

2019-05-15 05:11发布

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条回答
ら.Afraid
2楼-- · 2019-05-15 05:54

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.

查看更多
登录 后发表回答