minifyEnabled true在调试和发布模式下不起作用

时间:2018-08-03 09:48:23

标签: android obfuscation

我无法在调试和发布模式下使用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.**

错误如下,

  Copying resources from program jar [D:\SourceCode\app\build\intermediates\exploded-aar\com.android.support\support-v4\24.0.0\jars\libs\internal_impl-24.0.0.jar] (filtered)
  Copying resources from program jar [D:\SourceCode\log4j-1.2.17\log4j-1.2.17.jar] (filtered)
  Copying resources from program jar [D:\SourceCode\android-logging-log4j-1.0.3\android-logging-log4j-1.0.3.jar] (filtered)
  Copying resources from program jar [D:\SourceCode\app\build\intermediates\transforms\mergeJavaRes\release\jars\2\1f\main.jar] (filtered)
  Copying resources from program directory [D:\SourceCode\app\build\intermediates\classes\release] (filtered)
Printing classes to [D:\SourceCode\app\build\outputs\mapping\release\dump.txt]...
:app:transformClassesWithDexForRelease
To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 5120 MB.
To do this set org.gradle.jvmargs=-Xmx5120M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html
Error:Error converting bytecode to dex:
Cause: java.lang.RuntimeException: Exception parsing classes
Error:1 error; aborting
:app:transformClassesWithDexForRelease FAILED
Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> 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
Information:BUILD FAILED
Information:Total time: 6 mins 42.019 secs

这3天我一直在工作。请为此提供帮助。谢谢您

1 个答案:

答案 0 :(得分:1)

  

首先将multiDexEnabled添加为true

----    ---- Serving Responses
    ----     Background Work

并添加依赖项,例如

defaultConfig {
        minSdkVersion 15  // it will work fast
        targetSdkVersion 26
        multiDexEnabled true
    }

确保创建扩展的应用程序类,例如

dependencies {
  compile 'com.android.support:multidex:1.0.3'
}

MultiDexApplication.class

 <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>

注意:请确保将gradle和库升级到最新版本。

转到gradle.properties并增加堆大小。.我认为您的RAM小于8 GB。