Export jar file using Android Studio
Check out the library source code from the repository.
Import checkout library in your android studio.
Modify your build.gradle
If your current module is a library project then you need to properly recognize ‘android-library’ plugin as mention below.
apply plugin: 'com.android.library'
android {
compileSdkVersion 'Google Inc.:Google APIs:16'
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 13
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:support-v13:23.0.0'
}
task makeJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('build/outputs/')
include('classes.jar')
rename ('classes.jar', 'myLib.jar')
into('release/') //you can change this directory where you want to copy your .jar
}
task clearJar(type: Delete) {
delete 'build/libs/myLib.jar'
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 'Google Inc.:Google APIs:16'
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 13
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:support-v13:23.0.0'
}
task makeJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('build/outputs/')
include('classes.jar')
rename ('classes.jar', 'myLib.jar')
into('release/') //you can change this directory where you want to copy your .jar
}
task clearJar(type: Delete) {
delete 'build/libs/myLib.jar'
}
Run gradlew to make jar.
For generating .jar, follow below steps,
Open the terminal.
Move to your project root directory.
Call makejar function which you have added in build.gradle
Example :-> D:\Users\MyWorkspace\project > gradlew makejar
After following all above steps you will find “myLib.jar” under release folder.