1. 導入Library ,打開Library 的build gradle 在最外面添加以下:java
/** AVLView 自定義的jar 包名 **/
task clearJar(type: Delete) {
delete 'build/libs/AVLView.jar'
delete 'libs/AVLView.jar'
}
task makeJar(type:org.gradle.api.tasks.bundling.Jar) {
delete('build/libs/AVLView.jar')
baseName 'AVLView'
/***打包class 文件的路徑 **/
from('build/intermediates/classes/release/')
into('build/libs')
include('classes.jar')
rename('classes.jar','AVLView.jar')
}
makeJar.dependsOn(clearJar, build)
完整文件:android
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 33
versionName "2.1.3"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
/** AVLView 自定義的jar 包名 **/
task clearJar(type: Delete) {
delete 'build/libs/AVLView.jar'
delete 'libs/AVLView.jar'
}
task makeJar(type:org.gradle.api.tasks.bundling.Jar) {
delete('build/libs/AVLView.jar')
baseName 'AVLView'
/***打包class 文件的路徑 **/
from('build/intermediates/classes/release/')
into('build/libs')
include('classes.jar')
rename('classes.jar','AVLView.jar')
}
makeJar.dependsOn(clearJar, build)
2. 在Terminal 命令行 輸入: gradlew makeJar 等待Build Successful 。api
3. 如圖 jar aar app