Android minifyEnabled true 在调试和发布模式下不起作用
Posted
技术标签:
【中文标题】Android minifyEnabled true 在调试和发布模式下不起作用【英文标题】:Android minifyEnabled true is not working in Debug and Release mode 【发布时间】:2019-01-10 00:29:07 【问题描述】:我无法在调试和发布模式下使用 minifyEnabled true 运行 apk。我参考了以下链接,但没有一个对我有用。
1.android- Error:Execution failed for task ':app:transformClassesWithDexForRelease'
2.Error converting bytecode to dex: Cause: java.lang.RuntimeException: Exception parsing classes - Android studio 2.0 beta 6
下面是我的应用程序 build.gradle 文件
apply plugin: 'com.android.application'
android
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig
applicationId 'XX.XX.XXX'
minSdkVersion 21
targetSdkVersion 23
versionCode 9
versionName "1.0"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
sourceSets.main
jni.srcDirs = [] //disable automatic ndk-build call
jniLibs.srcDir 'src/main/libs' //integrate your libs from libs instead of jniLibs
dexOptions
javaMaxHeapSize "4g" //specify the heap size for the dex process
buildTypes
release
debuggable false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
debug
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
productFlavors
lintOptions
checkReleaseBuilds false
packagingOptions
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
dependencies
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
// compile files('libs/maflogonimo-1.210.3.jar')
compile project(':android-logging-log4j-1.0.3')
compile project(':log4j-1.2.17')
compile files('libs/gson-2.6.2.jar')
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.esri.arcgis.android:arcgis-android:10.2.8-1'
//GIS
compile(name:'ClientHubSLL-3.16.1', ext:'aar')
compile(name:'ClientLog-3.16.1', ext:'aar')
compile(name:'Common-3.16.1', ext:'aar')
compile(name:'Connectivity-3.16.1', ext:'aar')
compile(name:'CoreServices-3.16.1', ext:'aar')
compile(name:'DataVaultLib-3.16.1', ext:'aar')
compile(name:'E2ETrace-3.16.1', ext:'aar')
compile(name:'HttpConvAuthFlows-3.16.1', ext:'aar')
compile(name:'HttpConversation-3.16.1', ext:'aar')
compile(name:'MAFLogger-3.16.1', ext:'aar')
compile(name:'MAFLogonCore-3.16.1', ext:'aar')
compile(name:'ODataAPI-3.16.1', ext:'aar')
compile(name:'ODataOnline-3.16.1', ext:'aar')
compile(name:'Request-3.16.1', ext:'aar')
compile(name:'SupportabilityFacade-3.16.1', ext:'aar')
compile(name:'MAFCalendar-3.16.1', ext:'aar')
compile(name:'MAFLocaleAwareControls-3.16.1', ext:'aar')
compile(name:'MAFLogViewer-3.16.1', ext:'aar')
compile(name:'MAFSettingScreen-3.16.1', ext:'aar')
compile(name:'MAFTreeView-3.16.1', ext:'aar')
compile(name:'MAFUIComponents-3.16.1', ext:'aar')
compile(name:'XscriptParser-3.16.1', ext:'aar')
compile(name:'MAFLogonUI-3.16.1', ext:'aar')
compile(name:'MobilePlace-3.16.1', ext:'aar')
apply plugin: 'com.google.gms.google-services'
下面是我的 proguard-rules.pro 文件
-renamesourcefileattribute SourceFile
-keepattributes SourceFile, LineNumberTable
-keepattributes Exceptions, Signature
-keepattributes EnclosingMethod
-keepattributes InnerClasses
-keep class org.javarosa.** *;
-keep class com.sap.** *;
-keep class jcifs.** *;
-dontwarn com.google.**
-dontwarn org.apache.**
-dontwarn com.sap.**
-dontwarn au.com.bytecode.**
-dontwarn org.joda.**
-dontwarn android.content.**
-dontwarn android.graphics.**
-dontwarn android.util.**
-dontwarn android.view.**
-dontwarn javax.servlet.**
-dontwarn jcifs.http.**
-dontwarn org.codehaus.**
错误如下,
1.
Error:Error converting bytecode to dex:
Cause: java.lang.RuntimeException: Exception parsing classes
2.
Error:1 error; aborting
:app:transformClassesWithDexForDebug FAILED
3.
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_161\bin\java.exe'' finished with non-zero exit value 1
请帮我解决这个问题。在此先感谢。
【问题讨论】:
【参考方案1】:将此添加到您的 proguard-rules.pro
后尝试
-dontwarn javax.naming.**
-dontwarn javax.servlet.**
-dontwarn org.slf4j.**
如果你被 proguard 卡住了。那么请暂时删除它。
buildTypes
release
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
debug
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
【讨论】:
错误:将字节码转换为dex时出错:原因:java.lang.RuntimeException:异常解析类错误:1错误;中止 :app:transformClassesWithDexForDebug FAILED 错误:任务 ':app:transformClassesWithDexForDebug' 执行失败。 > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process .internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_161\bin\java.exe'' 以非零退出值 1 结束 这是默认错误,你必须得到详细的错误,尝试使用命令行--stacktrace 顺便说一下你为什么不删除proguard设置,如果你不想浪费时间,proguard就是删除未使用的类。但是,如果您遇到问题,那么只需删除 proguard。并且不要缩小 是 Khemraj,但如果 minifyEnabled 为 true,则无法保护项目 查看编辑的答案,评论所有与proguard相关的设置。以上是关于Android minifyEnabled true 在调试和发布模式下不起作用的主要内容,如果未能解决你的问题,请参考以下文章
Android 因 minifyEnabled 和 AWS 调用而崩溃
Android minifyEnabled true for firebase
Android Gradle 插件BuildType 编译类型配置 ④ ( minifyEnabled 配置 | multiDexEnabled | pseudoLocalesEnabled )
坑:Android Studio gradle minifyEnabled 为 true debug断点失效