Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert an Android Library Project to an External JAR?

Tags:

I have an Android library project that has been working for me pretty well, but now I am interested in "converting" it to an external JAR.

How do I do that?

Can any Android library project be converted to an external JAR? If not, what are the restrictions or limitations?

like image 328
uTubeFan Avatar asked Nov 01 '11 22:11

uTubeFan


People also ask

Can I install jar on Android?

Your Android device can run Java games and apps, but it isn't designed to do so, and hence you don't find any Java emulators on the Play Store to run jar files on Android devices.


2 Answers

Can any Android library project be converted to an external JAR?

Not right now.

If not, what are the restrictions or limitations?

If your library is purely Java code, with no resources, you can create a JAR out of the .class files, just as you would with regular Java.

If your library uses resources, you can still create a JAR as above. However, you will need to look up the R values (e.g., R.layout.main) via reflection or getIdentifier(), and your resources will not be packaged in the JAR but would have to be distributed separately.

In the future, the build tools should support creating distributable JAR files out of library projects, complete with resources. The current build tools do create JARs, but they are not designed to be distributed but are rather internal build artifacts at the moment.

like image 168
CommonsWare Avatar answered Sep 28 '22 04:09

CommonsWare


http://developer.android.com/guide/developing/projects/index.html#LibraryProjects claims that you can't export these to an external JAR. Specific quote:

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.

like image 39
Sinjo Avatar answered Sep 28 '22 02:09

Sinjo