Instant Run不适用于proguard

时间:2016-02-16 21:44:35

标签: android proguard

我正在研究Android Studio中的“即时运行”功能。但看起来它与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\1\5\slice_1 took 328
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\1\5\slice_0 took 340
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\1\5\slice_2 took 331
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\1\5\slice_5 took 321
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\1\5\slice_3 took 456

但是如果我将“minifyEnabled”设置为true,Gradle控制台中就不再有“即时运行”任务,要么是黄色霹雳按钮。

有没有让他们一起工作?

2 个答案:

答案 0 :(得分:2)

根据this官方Android开发者页面,Android Studio在使用即时游戏时会停用ProGuard。enter image description here

答案 1 :(得分:0)

1.转到'运行/调试配置'删除您的Android应用程序配置

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

3.转到杂项标签,取消选中“强制停止运行应用程序,然后再启动活动