Android Studio Instant 运行 始终重启应用程序

Android Studio Instant Run restart application always

在 Android Studio 中,"Instant Run" 函数 "Apply changes" restart application always, even if no change in code (Android Studio 2.3.0 - MacOS 10.12.3). This happen when application is in Debug and paused on a break point, if then I try to apply change the app restart

这是我的 build.gradle:

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}
buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}
allprojects {
    repositories {
        mavenCentral()
    }
}


android {
    compileSdkVersion 23
    buildToolsVersion '25.0.2'
    dexOptions {
        javaMaxHeapSize "4g"
    }
    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 23
        multiDexEnabled true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }



    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            resources.srcDirs = ['src/main/java']
            aidl.srcDirs = ['src/main/java']
            renderscript.srcDirs = ['src/main/java']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        //instrumentTest.setRoot('tests')
    }
}

根据 android docs:

禁用自动activity重启

执行热插拔时,您的应用会保留 运行,但 Android Studio 会自动重启当前的 activity。要禁用此默认设置:

打开“设置”或“首选项”对话框:

  • 在 Windows 或 Linux 上,select 菜单栏中的文件 > 设置。
  • 在 Mac OSX、select Android Studio > 菜单栏中的首选项。
  • 导航到“构建、执行、部署”>“即时”运行。
  • 在代码更改时取消选中重新启动 activity 旁边的复选框。

如果自动activity重启被禁用,您可以手动重启 通过 selecting 运行 > 重新启动菜单栏中的当前 activity Activity.

即时 运行 在调试器中始终被禁用:

On Android Studio 2.3, if you deploy your app by clicking Debug , pushing subsequent code changes by clicking Apply Changes always results in a cold swap. To learn more, go to issue #234401.

来自https://developer.android.com/studio/run/index.html#instant-run

除此之外,您的配置似乎选中了所有复选框。