Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Jar file in Android Studio

I have a library project in Android Studio. I want to generate a .jar file for this library. I need the jar file contain/include all the dependencies this Library project has.

The problem is I couldn't find a way of generating a jar file. Is there any way I can generate a jar file for my project?

Best Regards

like image 462
user2498079 Avatar asked Feb 25 '15 08:02

user2498079


People also ask

How do you create a jar file?

Open the Jar File wizard In the Package Explorer select the items that you want to export. If you want to export all the classes and resources in the project just select the project. Click on the File menu and select Export. In the filter text box of the first page of the export wizard type in JAR.

What is JAR file in Android Studio?

A JAR (Java Archive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file to distribute application software or libraries on the Java platform.

Can I run a .jar file 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.


1 Answers

Here is an example of Gradle task which creates .jar from classes.jar.

classes.jar file can be found in /build/intermediates/exploded-aar/ folder.

Edit: Create jar file for every Android Library project and distribute them standalone. What about dependencies required by library projects - add those dependencies in final project, where your library will be used.

For example: you Android Library project MyLibProject, which has following dependencies in build.gradle

dependencies {
    compile "com.android.support:support-v4:19.+"
}

When you'll build your project you'll get classes.jar for MyLibProject, and those classes.jar will contain just class from library project, but not from com.android.support:support-v4:19.+.

After that in another project you add classes.jar as library dependency in build.gradle and also define same dependencies as in MyLibProject.

And if you still need fatJar, look here how to create fatJar with Gradle.

like image 191
Veaceslav Gaidarji Avatar answered Oct 11 '22 07:10

Veaceslav Gaidarji