即时运行比标准版本更长

时间:2016-12-27 15:32:47

标签: android android-studio android-instant-run

现在已经有一段时间了,Instant Run不再工作了,也就是说,它比标准版本慢。

AOSP错误跟踪器中有一些材料,但我无法解决这个问题。我相信你们中的一些人会帮忙。

没有即时运行

构建需要大约1.30分钟。

使用即时运行

我第一次运行应用程序,然后应用一些小的更改。例如,在方法内更改int a = 1int a = 2,或者更改字符串。

然后再次点击运行。会发生什么:

  • 看似完整的构建(在我的所有模块上调用assembleDebug)。大概需要1.30分钟。
  • 第二轮继续,仅调用app:assembleDebug。大约需要一分钟:

    16:27:10 Executing tasks: [:app:assembleDebug]
    16:28:16 Gradle build finished in 1m 5s 264ms
    16:28:22 Instant Run applied code changes and restarted the app.
    

在第一轮中,没有任何输出到事件日志或Gradle控制台。在第二轮中,Gradle控制台输出大量内容并以

结束
BUILD SUCCESSFUL

Total time: 51.385 secs
PREDEX CACHE HITS:   0
PREDEX CACHE MISSES: 45
Stopped 0 compiler daemon(s).

我该怎么办?

我在grade.properties文件中有这些:

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true

build.gradle个文件中没有与dex相关的内容。不使用杰克。 Android Studio 2.2.3。

gradle.properties文件

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true

ANDROID_BUILD_MIN_SDK_VERSION=15
ANDROID_BUILD_TARGET_SDK_VERSION=25
ANDROID_BUILD_SDK_VERSION=25
ANDROID_BUILD_TOOLS_VERSION=25.0.2

项目级别build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

主模块build.gradle

(我还有其他两个'图书馆'模块)

apply plugin: 'com.android.application'

Properties signProp = new Properties()
signProp.load(new FileInputStream(file(project.property("SIGN_PROPS"))))

Properties authProp = new Properties()
authProp.load(new FileInputStream(file(project.property("AUTH_KEYS_PROPS"))))


def PARSE_APPLICATION_ID = '"' + authProp['parseApplicationId'] + '"';
def PARSE_CLIENT_KEY = '"' + authProp['parseClientKey'] + '"'
def PARSE_SERVER_URL = '"' + authProp['parseServerURL'] + '"'
def GOOGLE_PLAY_API_KEY = '"' + authProp['googlePlayApiKey'] + '"'


android {
    signingConfigs {
        release_config {
            keyAlias signProp['keyAlias']
            keyPassword signProp['keyPassword']
            storeFile file(signProp['storeFilePath'])
            storePassword signProp['storePassword']
        }
    }
    compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
    buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

    defaultConfig {
        minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
        versionCode 21
        versionName "1.3.3"

        buildConfigField 'String', 'PARSE_APPLICATION_ID', PARSE_APPLICATION_ID
        buildConfigField 'String', 'PARSE_CLIENT_KEY', PARSE_CLIENT_KEY
        buildConfigField 'String', 'PARSE_SERVER_URL', PARSE_SERVER_URL
        buildConfigField 'String', 'GOOGLE_PLAY_API_KEY', GOOGLE_PLAY_API_KEY

        signingConfig signingConfigs.release_config
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {

        release {
            minifyEnabled true
            shrinkResources true
        }

        debug {
            minifyEnabled false
            shrinkResources false
        }
    }
    productFlavors {
    }

}

dependencies {

    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.android.support:preference-v14:24.2.1'
    compile 'com.google.maps.android:android-maps-utils:0.4.3'
    compile 'com.google.android.gms:play-services-maps:9.2.1'
    compile 'com.google.android.gms:play-services-appinvite:9.2.1'
    compile 'com.google.android.gms:play-services-location:9.2.1'
    compile 'com.google.android.gms:play-services-appindexing:9.2.1'
    compile ('com.facebook.android:facebook-android-sdk:4.16.1') {
        exclude module: 'bolts-tasks'
    }

    compile 'com.parse.bolts:bolts-tasks:1.4.0'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.parse:parse-android:1.13.1'
    compile ('com.parse:parseui-widget-android:0.0.1') {
        exclude module: 'parse-android' 
    }

    compile project(':dateTimePicker')
    compile project(':commons')


}

apply plugin: 'com.google.gms.google-services'

4 个答案:

答案 0 :(得分:1)

http://tools.android.com/recent/androidstudio223isnowavailable

更新到最新版本的Android Studio,然后根据您的系统内存增加(studio.vmoptions)中的内存配置文件

    -Xms256m
    -Xmx1280m
-XX:MaxPermSize=350m

答案 1 :(得分:1)

如果您使用的是Google Play服务,请确保您没有在Gradle构建脚本中使用此服务:

compile 'com.google.android.gms:play-services:8.3.0'

仅使用您的应用实际使用的那些Google API。如果你使用的只是谷歌地图,你可以使用:

com.google.android.gms:play-services-maps:8.3.0

当我这样做时,我的编译时间从2分钟到大约25秒。有关您可以有选择地编译的Google API的列表,请参阅:

https://developers.google.com/android/guides/setup

答案 2 :(得分:1)

启用即时运行

  1. 打开“设置”或“偏好设置”对话框。
  2. 导航至构建,执行,部署>即时跑步。
  3. 选中启用即时运行旁边的复选框。
  4. 即时游戏的限制。

    部署到多个设备, 对您的应用进行多索引, 使用第三方插件, 推动对多进程应用程序的更改, 在工作资料中启动您的应用。

    如果您的应用使用multidex支持(multiDexEnabled true),则minSdkVersion必须为21或更高。否则,android studio会禁用Instant Run。

    gradle版本的Android插件必须为2.1.0或更高版本

    启用离线工作Android工作室加速:

    转到 文件>>设置或只需按ctrl + alt + s

    file>>设置>>摇篮。请检查Global Gradle设置下的离线工作

    提高Gradle效果

    打开android studio后,从android studio的右侧打开 gradle.properties 文件并添加以下两行。

      org.gradle.jvmargs=-Xmx1536m  
      org.gradle.daemon=true
      org.gradle.parallel=true
    

    在buildTypes中配置调试的构建变体

    debug {
            minifyEnabled false
            applicationIdSuffix ".debug"
        }
    

    更改后,您应该重新启动Android Studio。

    注意:构建时间取决于您的处理器和RAM。   我注意到(i7-3610qm,8gb ram)当你同时编译4个android studio项目然后在窗口响应慢。在构建过程完成后,pc工作正常。

答案 3 :(得分:-1)

保持bulit版本和目标版本相同