borges
borges

Reputation: 3687

Reference external project library source tree

First of all, I've know there are several questions targeting this topic, but none of them helped me.


I'm developing my first Android project with Android/ADT plugin and I want to use this library. I searched here in SO and in the official documentation how to accomplish this and I found how to reference a library project.

I ran the following command:

$ android update project --target 8 /path/to/workspace/myproject /path/to/workspace/numberpicker/lib
Resolved location of library project to: /path/to/workspace/numberpicker/lib
Updated project.properties
Updated local.properties
No project name specified, using Activity name 'SplashActivity'.
If you wish to change it, edit the first line of build.xml.
Added file /path/to/workspace/myproject/build.xml
Updated file /path/to/workspace/myproject/proguard-project.txt

Apparently this step worked correctly. But when I try to reference com.michaelnovakjr.numberpicker.NumberPicker in a xml layout the Eclipse complains it fails to find this class.

Then I found this answer and changed my project.properties:

# Before
android.library.reference.1=/path/to/workspace/numberpicker/lib
# After
android.library.reference.1=../numberpicker/lib

But didn't solve my problem.

Perhaps it is important to mention that this library is not a Eclipse project, so I can not open it in Eclipse.

Upvotes: 1

Views: 978

Answers (1)

yorkw
yorkw

Reputation: 41126

Library Project must exist in the same workspace in order to let Eclipse properly build the dependent project, See dev guide Managing Project - Library Projects for more details:

However, a library project differs from an standard Android application project in that you cannot compile it directly to its own .apk and run it on an Android device. Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library. Instead, you must compile the library indirectly, by referencing the library in the dependent application and building that application.

When you build an application that depends on a library project, the SDK tools compile the library into a temporary JAR file and uses it in the main project, then uses the result to generate the .apk. In cases where a resource ID is defined in both the application and the library, the tools ensure that the resource declared in the application gets priority and that the resource in the library project is not compiled into the application .apk. This gives your application the flexibility to either use or redefine any resource behaviors or values that are defined in any library.

In order to use numberpicker library, you need imported it as an Android Project in Eclipse, choose File -> New -> Other ... -> Android -> Android project, in the wizard window, check Create projet from existing source and choose the location.

Upvotes: 1

Related Questions