【问题标题】:Instant Run takes longer than standard buildsInstant Run 比标准构建需要更长的时间
【发布时间】:2017-05-11 21:40:46
【问题描述】:

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

AOSP 错误跟踪器中有一些材料,但我无法解决。我相信你们中的一些人会提供帮助。

没有即时运行

构建大约需要 1.30 分钟。

即时运行

我是第一次运行该应用程序,然后应用了一些小的更改。例如,在方法中将int a = 1 更改为int 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'

【问题讨论】:

  • 可能是因为这个错误code.google.com/p/android/issues/detail?id=206698?,我不知道你有什么版本
  • @Dasser 是的,谁知道呢?似乎只是一份抱怨的名单,而不是一份错误报告。
  • 您已阅读 the limitations of instant run 并确保您的项目不会成为所列陷阱之一的受害者,是吗?
  • @Vince 我现在有,没有陷阱。它曾经也可以工作。最近几次更新发生了一些变化,但我一看到问题就没有时间追踪问题。
  • @natario 这是针对特定项目还是任何项目?

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


【解决方案1】:

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

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

    -Xms256m
    -Xmx1280m
-XX:MaxPermSize=350m

【讨论】:

  • 已经在使用 2.2.3,并且已经在构建文件中设置了一些参数,正如您在问题中看到的那样。如果您对此进行扩展,我可以尝试调整它们,但我以前尝试过。
【解决方案2】:

如果您使用的是 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

【讨论】:

  • 是的,我已经这样做了。此外,不仅仅是编译需要很多时间;奇怪的问题还在于编译发生了两次。
【解决方案3】:

启用即时运行

  1. 打开“设置”或“首选项”对话框。
  2. 导航至构建、执行、部署 > 即时运行。
  3. 选中启用即时运行旁边的框。

Instant Run 的限制。

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

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

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

启用离线工作 android studio 加速:

转到文件>>设置或简单地按ctrl + alt + s

文件>>设置>> Gradle。请检查全局 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 with 8gb ram)当您同时编译 4 个 android studio 项目然后在窗口上响应缓慢。构建过程完成后电脑工作正常。

【讨论】:

  • @natario 请检查项目级别 build.gradle ===== task clean(type: Delete) { delete rootProject.buildDir }
  • 不要将Android上下文类放在静态字段中;这是内存泄漏,也会破坏 Instant Run
【解决方案4】:

保持内置版本和目标版本相同

【讨论】:

  • 请添加详细信息。这是一个赏金问题
  • 我是,构建版本是 25,目标版本是 25,构建工具版本是 25.0.2 在我的所有模块中。
  • compileSdkVersion 23, buildToolsVersion "23.0.3", minSdkVersion 11, targetSdkVersion 23, 通过维护这一切我解决了问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-16
  • 1970-01-01
  • 2019-05-22
  • 2021-07-02
  • 1970-01-01
  • 2014-05-06
  • 1970-01-01
相关资源
最近更新 更多