Sunday, 1 September 2013

Eclipse - How to add a non-Android library project to an Android app?

Eclipse - How to add a non-Android library project to an Android app?

Folks,
I have three projects in my Eclipse workspace:
A maven-based library project that generates a .jar file. This project
contains our core code.
A maven-based Java desktop application. This app is dependent upon the
library project.
An Android application that we just started to build. It is not yet
mavenized.
I would like the Android application to use the library project as the
dependency.
I have read a few responses to similar questions about adding library file
dependency to an Android application and I tried to follow them:
Method #1:
Project->Properties->Java Build Path->Projects-->Add and add the library
project.
Now, I can use the classes from the library project. Compiler does not
produce any warning. However, when I run the application on the emulator,
I get a class-not-defined error.
Method #2:
Copy the generated .jar file into "libs" directory of the Android app.
This works. There is no class-not-defined exception. However, I cannot
attach the source and therefore cannot step through the library code.
Plus, each time the source changes, I will have to manually copy the .jar
file over.
Method #3:
Go to Properties of the library project. You will see "Android" in the
left pane. Select it and mark "IsLibrary" field.
In my case, however, there is no "Android" property in the left pane. I
guess this property is shown only if it is a genuine Android library
project.
I am stuck. I would appreciate it if someone can tell me how to best deal
with this situation.
Here is a summary of what I wish to achieve: 1. The same library project
to be used in a desktop application as well as the Android application. 2.
On the Android application, source code debugging should work. 3. If there
is any source code change in the library application, the Android
application should automatically pick up the new changes (instead of me
trying to drag the new .jar file into the libs folder each time).
Thank you in advance for your help.
Regards,
Peter

No comments:

Post a Comment