Android库:使用Proguard时,释放.aar将classes.jar清空 [英] Android Library: Release .aar getting classes.jar empty when using proguard
问题描述
我正在尝试使用 minifyEnabled true 生成一个库,但是,在版本.aar中,classes.jar变空了.
I'm trying to generate a library with minifyEnabled true but, inside the release .aar, classes.jar is getting empty.
我已经检查了我的 proguard-rules.pro ,看来还可以.
I have checked my proguard-rules.pro and it seems to be all right.
我什至用默认的.gradle文件创建了一个新模块,当我将 minifyEnable设置为true 时,发行版仍会获取没有类的class.jar.
I've even created a new module with the default .gradle files and when i set minifyEnable true the release version still gets the classes.jar with no class inside.
毕竟,是否可以生成一个使代码模糊的android库?
After all, is it possible to generate an android library obfuscating the code?
添加模块build.gradle
EDIT 1: Adding module build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion '27.0.0'
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'org.apache.httpcomponents:httpcore:4.3.3'
compile('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
}
compile 'fr.bmartel:jspeedtest:1.25'
compile "com.android.support:appcompat-v7:27.0.0"
testCompile 'junit:junit:4.12'
}
推荐答案
好的,一段时间后,我解决了问题.
Ok, after some time I solved my problem.
我将默认的Proguard规则配置(library.pro)复制/粘贴到我的 proguard-rules.pro 中.您可以在您的sdk路径/tools/proguard/examples 中找到此文件和更多示例.
I copy/paste a default proguard rules configuration (library.pro) to my proguard-rules.pro. You can find this file and more examples in path-to-your-sdk/tools/proguard/examples.
有关更多信息,请阅读此.
For more information, read this.
在我的 build.gradle 中,我改变了:
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
收件人:
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'proguard-rules.pro' //added this line
}
}
感谢您的帮助!
这篇关于Android库:使用Proguard时,释放.aar将classes.jar清空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!