roy_lennon
roy_lennon

Reputation: 807

Create Android Library project jar

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!

Upvotes: 1

Views: 69

Answers (1)

user4400167
user4400167

Reputation:

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.

Upvotes: 1

Related Questions