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
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.
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.
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.
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 Librar
y 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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With