1、打开android studio选择File->New->New Module...
选择Android Library,创建一个Android Library的jar包工程
2、打开工程中的build.gradle
在文件末尾添加如下脚本
task deleteOldJar(type:Delete) {
delete 'build/libs/APPTest.jar'
}
task exportJar(type:Copy) {
from('build/intermediates/bundles/default/')
into('build/libs')
include('classes.jar')
rename('classes.jar','APPTest.jar')
}
exportJar.dependsOn(deleteOldJar,build)
APPTest.jar为要生成的jar文件名,生成的jar路径在工程中的build/libs目录下
完整文件如下:
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:22.2.1'
testCompile 'junit:junit:4.12'
}
task deleteOldJar(type:Delete) {
delete 'build/libs/APPTest.jar'
}
task exportJar(type:Copy) {
from('build/intermediates/bundles/default/')
into('build/libs')
include('classes.jar')
rename('classes.jar','APPTest.jar')
}
exportJar.dependsOn(deleteOldJar,build)
3、在Android Studio中选择Gradle projects->APPTest工程->Tasks->other->exportJar,双击exportJar生成jar包。
————————————————
版权声明:本文为CSDN博主「宝贝等等我」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/croop520/article/details/79930803