How to create a jar in Android studio?

how to create a jar file from android studio

  • I have a fairly latest version of android studio, I have created a module under a project which is basically supposed to be a library, when I build it, it creates an ".aar" file , what I want is .jar file as this library is supposed to be used with eclipse as well. The library contains activity as well, is there any way by which I can create a .jar file which I can use on Eclipse as well Android Studio ? I have already created this module and tried building , as a result it generated .aar file and not a .jar file.

  • Answer:

    Currently gradle based builds doesnt seems to be allowing to create jar with android studio, I decided to go for Intelij it has necessary option and does what i want , i can use community edition. ***Update**** Even the jar produced by Intelij with resources don't work , obviously its not easy to have a jar with resource , so decided to opt for .aar and hoping that Eclipse also gets support for .aar when gradle supports lands there, as that was my main concern.

vishal at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

I found a way to achieve this, plain simple, using Gradle 2.2.1: task jar(type: Jar, dependsOn: 'assembleRelease') { from fileTree(dir: 'build/intermediates/classes/release') } Place this in your library module. It will compile it as release and produce a JAR file in: build/libs. bash gradlew jar or use your IDE to target that jar Gradle task.

shkschneider

From https://github.com/jitpack/android-example/blob/master/library/build.gradle, I guess this will do: // uncomment to build a jar file in addition to the default aar file android.libraryVariants.all { variant -> def name = variant.buildType.name def task = project.tasks.create "jar${name.capitalize()}", Jar task.dependsOn variant.javaCompile task.from variant.javaCompile.destinationDir artifacts.add('archives', task); } It should make your builds generate a JAR along with the regular AAR file.

shkschneider

aar is not related to AS or eclipse but is an AndroidARchive for Android applications like JavaARchives are for java applications. Because Android is java based, jars can be used. But to take android specialities into account, like resource bundles, an aar is the right thing to use.

SatelliteSD

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.