为什么proguard在我的debug multidex构建中运行?

时间:2016-09-01 19:10:11

标签: android gradle proguard android-proguard

配置

  • Mutlidex已启用。
  • MinifyEnabledtrue release

Gradle buildscript:

buildscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        classpath "com.android.tools.build:gradle:2.1.3"
    }
}

Android DSL配置:

android {
    defaultConfig {
        multiDexEnabled true
    }

    signingConfigs {
        debug {

        }

        release {

        }
    }

    buildTypes {
        debug {
            versionNameSuffix ".debug"
        }

        release {
            signingConfig signingConfigs.release
            minifyEnabled true
            proguardFile getDefaultProguardFile("proguard-android.txt")
            proguardFile "proguard-project.txt"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    dexOptions {
        jumboMode true
        javaMaxHeapSize "4g"
    }

    dataBinding {
        enabled = true
    }
}

gradlew assembleDebug的输出:

:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:prePackageMarkerForDebug
:app:transformClassesWithJarMergingForDebug
:app:collectDebugMultiDexComponents UP-TO-DATE
:app:transformClassesWithMultidexlistForDebug
ProGuard, version 5.2.1
Reading program jar [/<>/build/intermediates/transforms/jarMerging/debug/jars/1/1f/combined.jar]
Reading library jar [/<>/build-tools/23.0.3/lib/shrinkedAndroid.jar]
Preparing output jar [/<>/build/intermediates/multi-dex/debug/componentClasses.jar]
  Copying resources from program jar [/<>/build/intermediates/transforms/jarMerging/debug/jars/1/1f/combined.jar]
:app:transformClassesWithDexForDebug
:app:mergeDebugJniLibFolders UP-TO-DATE
:app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug
:app:zipalignDebug
:app:assembleDebug

BUILD SUCCESSFUL

Total time: 1 mins 0.285 secs

我试过了:

buildTypes {
    debug {
        debuggable true
        minifyEnabled false
    }

    release {
        debuggable false
        minifyEnabled true
    }
}

参考文献:

2 个答案:

答案 0 :(得分:2)

使用multidex将类拆分为多个dex文件时,Android插件将在内部使用 ProGuard 来确定哪些类必须保存在主classes.dex中。

此执行与您自己的规则或minifyEnabled标志无关,可以安全地忽略,尽管日志输出可能很烦人。要禁止显示日志消息,可以将以下内容添加到build.gradle:

tasks.whenTaskAdded { task ->
  if (task.name.startsWith("transformClassesWithMultidexlistFor")) {
    task.logging.level = LogLevel.ERROR
  }
}

答案 1 :(得分:0)

您需要在minifyEnabled false构建类型中指定debug。创建新项目时,通常会默认存在。你似乎把它删除了。