Instant 运行 不适用于混淆器

Instant Run doesn't work with proguard

我正在研究 Android Studio 中的 "instant run" 功能。但看起来它不适用于proguard。有没有人知道为什么以及如何让他们一起工作?

我的环境:Android Studio 2.0 Beta 4

我的最高等级build.gradle

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-beta4'
    }
}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        mavenCentral()
        jcenter()
    }
}

模块的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 23
    }
    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:23.1.1'
}

使用上述设置,我可以在 gradle 控制台中看到一些后续 "instatn run" 任务。并且 运行 按钮出现黄色雷电。

:TestIR:transformClassesWithInstantRunVerifierForDebug
:TestIR:transformClassesWithInstantRunForDebug
:TestIR:transformClasses_enhancedWithInstant+reloadDexForDebug
:TestIR:generateDebugInstantRunAppInfo
:TestIR:transformClassesWithInstantRunSlicerForDebug
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\slice_1 took 328
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\slice_0 took 340
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\slice_2 took 331
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\slice_5 took 321
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\slice_3 took 456

但是,如果我将 "minifyEnabled" 设置为 true,Gradle 控制台中将不再有 "instant run" 任务,无论是黄色的雷电按钮。

有没有办法让他们一起工作?

1.Go 到 'run/debug configurations' 删除您的 android 应用程序配置

2.重新创建 android 应用程序配置

3.Go到杂项选项卡,取消勾选'force stop 运行 application before launching activity'

根据this official Android developer page, Android Studio disables ProGuard when using Instant Run.