插件地址:https://github.com/adisonhyh/buildJar
首先贴build.gradle
apply plugin: 'com.android.application'
apply plugin: 'jar-gradle-plugin'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.icuesocketpackage"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
//混淆一定要把这一项设置为true否者会失败
minifyEnabled true
//去除無用resource文件
shrinkResources true
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:25.3.1'
testCompile 'junit:junit:4.12'
}
BuildJar {
//输出目录
outputFileDir = project.buildDir.path + "/jar"
//输出原始jar包名
outputFileName = "test.jar"
//输出混淆jar包名
outputProguardFileName = "test_proguard.jar"
//混淆配置
proguardConfigFile = "proguard-rules.pro"
//是否需要默认的混淆配置proguard-android.txt
needDefaultProguard = true
applyMappingFile = "originMapping/mapping.txt"
//需要输出jar的包名列表,当includePackage&includeClass为空时,则默认全项目输出,支持多包,如 includePackage=['com/test/example1','com/test/example2'...]
includePackage = ['com/test/example']
//不需要输出jar的包名列表,同上用法
excludePackage = ['android/support/v7']
}
设置完还需要设置根目录的build.gradle依赖
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.adison.gradleplugin:jar:1.0.2'
}
最重要需要一个映射文件文件放在根app目录下面
http://download.youkuaiyun.com/detail/ctrlxcs13/9923836
本文介绍如何使用Gradle插件为Android应用程序构建jar包,包括配置build.gradle文件,设置依赖以及创建混淆映射文件等步骤。
1万+

被折叠的 条评论
为什么被折叠?



