1

I have a project that is an Android Library. It uses two external jars (universal image loader and ksoap).

I need to create a jar from this project to distribute it, but when I do this and use this project, I always get a java.lang.NoClassDefFoundError, saying that the ksoap classes are not found.

When I open the jar file, I see the both jars included, but it seems that the final project does not see them.

How can I do this?

Thanks!

7
  • You can't distribute an Android Library Project by jar. The reason is that jar files can't include assets and resources. So if your project has any of these, you need to distribute it as source. Commented Jul 7, 2014 at 19:15
  • Thank you @GabeSechan . Is that the only way? I am not able to distribute this project as a source... Commented Jul 7, 2014 at 19:21
  • If you have no assets and no resources, you can make a jar. But jars won't work if you need either of those. You may be able to get away with assets by having the library user add them to their project as assets, but I don't think resources will work that way, as you won't be able to have access to the R file in the library without them. There may be a workaround, but it won't be nice. Commented Jul 7, 2014 at 19:24
  • However, you can make files in raw folders work for you when you distribute as a jar, so there are ways to distribute files along with an android library jar if need be. Commented Jul 7, 2014 at 19:25
  • Thanks. I only need two external jars, but as far as I can see, it is not possible to create a jar that uses external jars. Commented Jul 7, 2014 at 19:30

1 Answer 1

1

Create a regular Java library and do the following steps:

  • Add "android.jar" as a library in your project
    How to locate it?
    android.jar is located in Android SDK

    <Android SDK path> / platforms / android-XX / android.jar (XX = API number)
    It's simple to do, and it not requires to include "android.jar" in your JAR file, because "android.jar" is already included by default in Eclipse ADT / Android Studio.
    NOTE:

For Android Studio, add the library uniquely in this way:
Add this on your build.gradle.

dependencies { compile files('libs/your-jar-library.jar') } 

For include these two external jars, you need to do following steps:

  • Unzip both JARS
  • Unzip your JAR file
  • Copy the files of the unzipped libraries to your unzipped JAR (Only package folders)
  • Zip your JAR file with the external libraries included, you don't need to put a JAR inside JAR.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.