我想让一个库jar包含所有依赖项,但是不使用的东西会被删除。
android {
compileSdkVersion 19
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//compile 'com.google.android.gms:play-services:5.+'
compile 'com.nimbusds:nimbus-jose-jwt:4.11.2'
compile 'com.madgag.spongycastle:core:1.54.0.0'
compile 'com.madgag.spongycastle:prov:1.54.0.0'
compile 'com.madgag.spongycastle:pkix:1.54.0.0'
compile 'org.bouncycastle:bcprov-jdk15on:1.54'
compile 'org.bouncycastle:bcpkix-jdk15on:1.54'
compile 'com.google.code.gson:gson:2.8.1'
}
android.libraryVariants.all { variant ->
task("jar${variant.name}", type: Jar) {
description "Bundles compiled .class files into a JAR file for $variant.name."
dependsOn variant.javaCompile
from variant.javaCompile.destinationDir
exclude '**/R.class', '**/R$*.class', '**/R.html', '**/R.*.html'
baseName = 'myLib'
}
}
task jarTask(type: Jar) {
baseName="myLib"
from 'src/main/java'
}
task includeAll(type: Jar) {
baseName = "myLib"
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
with jarTask
}
configurations {
jarConfiguration
}
artifacts {
jarConfiguration jarTask
}
目前,我正在使用gradle clean includeall
来创建jar。如何剥离所有未使用的东西?
要求因为我必须为BC导入javax.naming.Binding
,导入更多东西似乎很疯狂且不需要。
我需要什么 - 独立jar包含所有依赖项,但不使用的方法/类被删除。