即时运行比标准构建需要更长的时间

时间:2021-11-10 13:03:41

It’s been some time now that Instant Run is not working anymore, that is, it’s slower than standard builds.

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

There’s some material in the AOSP bug tracker, but I could not work this out. I’m sure some of you will help.

在AOSP bug跟踪器中有一些资料,但我无法解决。我相信你们中的一些人会帮忙的。

Without Instant Run

Builds take about 1.30 min.

构建大约需要1.30分钟。

With Instant Run

I run the app for the first time, then apply some minor change. For example, change int a = 1 to int a = 2 inside a method, or alter a string.

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

Then click run again. What happens:

然后再次单击“运行”。发生了什么:

  • A seemingly full build takes place (calling assembleDebug on all my modules). Takes about 1.30 min.
  • 一个看似完整的构建发生了(在我的所有模块上调用assembleDebug)。大约需要1.30分钟。
  • A second round goes on, calling just app:assembleDebug. It takes about another minute:

    第二个回合继续,只调用应用程序:汇编调试。又花了一分钟:

    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.
    

During the first round, no output whatsoever to Event Log or Gradle Console. During second round, the Gradle Console outputs lots of stuff and ends with

在第一轮中,没有任何输出到事件日志或分级控制台。在第二轮中,Gradle控制台会输出很多东西,并以结束

BUILD SUCCESSFUL

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

What can I do?

I have these in my grade.properties file:

这些在我的年级里。属性文件:

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

Nothing dex related in build.gradle files. Not using Jack. Android Studio 2.2.3.

德克斯与建筑没有任何关系。gradle文件。不使用杰克。2.2.3 Android工作室。


gradle.properties file

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

Project level 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()
    }
}

Main module build.gradle

(I have other two ‘library’ modules also)

(我还有另外两个' library '模块)

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 个解决方案

#1


1  

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

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

Update to the latest version of Android Studio and then increase the memory profile in (studio.vmoptions) based on your system memory

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

    -Xms256m
    -Xmx1280m
-XX:MaxPermSize=350m

#2


1  

If you are using Google Play services, make sure you aren't using this in your Gradle build script:

如果您正在使用谷歌游戏服务,请确保您没有在您的Gradle构建脚本中使用它:

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

Only use those Google APIs that your app is really using. If all you are using is Google Maps, you would use this:

只使用你的应用真正使用的谷歌api。如果您所使用的是谷歌地图,您将使用以下方法:

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

When I did this, my compile time went from over 2 minutes to around 25 seconds. For a list of the Google apis that you can selectively compile against, see:

当我这样做时,编译时间从2分钟增加到25秒。对于您可以选择性编译的谷歌api的列表,请参见:

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

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

#3


1  

Enable Instant Run

启用即时运行

  1. Open the Settings or Preferences dialog.
  2. 打开设置或首选项对话框。
  3. Navigate to Build, Execution, Deployment > Instant Run.
  4. 导航到构建、执行、部署>即时运行。
  5. check the box next to Enable Instant Run.
  6. 选中旁边的复选框以启用即时运行。

Limitations of Instant Run.

即时运行的局限性。

Deploying to multiple devices, Multidexing your app, Using third-party plugins, Pushing changes to multi-process apps, Launching your app in a Work profile.

部署到多个设备,多路复用你的应用,使用第三方插件,推动对多进程应用的改变,在工作概要中启动你的应用。

If you use multidex support (multiDexEnabled true) for your app, minSdkVersion must be 21 or higher. Otherwise, android studio disables Instant Run.

如果应用程序使用multidex支持(multiDexEnabled true),那么minSdkVersion必须是21或更高。否则,android studio将禁止即时运行。

Android plugin for gradle version must be 2.1.0 or higher

升级版的Android插件必须是2.1.0或更高

Enable Offline Work android studio to speed up:

支持离线工作android studio加速:

Go to file >> settings or simply press ctrl + alt + s

进入文件>>设置或简单按ctrl + alt + s

file >> settings >> Gradle. please check Offline work under Global Gradle setting

文件>>设置>>级。请在全球等级设置下查询离线工作

Improve Gradle Performance

提高它的性能

After opening android studio, open gradle.properties file from right side of android studio and add the following two lines.

android studio开放后,开放等级。从android studio的右侧添加属性文件,并添加以下两行。

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

Configure Build Variants of debug in buildTypes

在构建类型中配置调试的构建变体

debug {
        minifyEnabled false
        applicationIdSuffix ".debug"
    }

After changes, you should restart your Android Studio.

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

Note: Build time depend on your processor and RAM. I noticed in (i7-3610qm with 8gb ram) when you compile 4 android studio project at same time then slow respond on window. after build process finish pc works normal.

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

#4


-1  

Maintain bulit versions and target version as same

维护bulit版本和目标版本

#1


1  

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

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

Update to the latest version of Android Studio and then increase the memory profile in (studio.vmoptions) based on your system memory

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

    -Xms256m
    -Xmx1280m
-XX:MaxPermSize=350m

#2


1  

If you are using Google Play services, make sure you aren't using this in your Gradle build script:

如果您正在使用谷歌游戏服务,请确保您没有在您的Gradle构建脚本中使用它:

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

Only use those Google APIs that your app is really using. If all you are using is Google Maps, you would use this:

只使用你的应用真正使用的谷歌api。如果您所使用的是谷歌地图,您将使用以下方法:

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

When I did this, my compile time went from over 2 minutes to around 25 seconds. For a list of the Google apis that you can selectively compile against, see:

当我这样做时,编译时间从2分钟增加到25秒。对于您可以选择性编译的谷歌api的列表,请参见:

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

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

#3


1  

Enable Instant Run

启用即时运行

  1. Open the Settings or Preferences dialog.
  2. 打开设置或首选项对话框。
  3. Navigate to Build, Execution, Deployment > Instant Run.
  4. 导航到构建、执行、部署>即时运行。
  5. check the box next to Enable Instant Run.
  6. 选中旁边的复选框以启用即时运行。

Limitations of Instant Run.

即时运行的局限性。

Deploying to multiple devices, Multidexing your app, Using third-party plugins, Pushing changes to multi-process apps, Launching your app in a Work profile.

部署到多个设备,多路复用你的应用,使用第三方插件,推动对多进程应用的改变,在工作概要中启动你的应用。

If you use multidex support (multiDexEnabled true) for your app, minSdkVersion must be 21 or higher. Otherwise, android studio disables Instant Run.

如果应用程序使用multidex支持(multiDexEnabled true),那么minSdkVersion必须是21或更高。否则,android studio将禁止即时运行。

Android plugin for gradle version must be 2.1.0 or higher

升级版的Android插件必须是2.1.0或更高

Enable Offline Work android studio to speed up:

支持离线工作android studio加速:

Go to file >> settings or simply press ctrl + alt + s

进入文件>>设置或简单按ctrl + alt + s

file >> settings >> Gradle. please check Offline work under Global Gradle setting

文件>>设置>>级。请在全球等级设置下查询离线工作

Improve Gradle Performance

提高它的性能

After opening android studio, open gradle.properties file from right side of android studio and add the following two lines.

android studio开放后,开放等级。从android studio的右侧添加属性文件,并添加以下两行。

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

Configure Build Variants of debug in buildTypes

在构建类型中配置调试的构建变体

debug {
        minifyEnabled false
        applicationIdSuffix ".debug"
    }

After changes, you should restart your Android Studio.

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

Note: Build time depend on your processor and RAM. I noticed in (i7-3610qm with 8gb ram) when you compile 4 android studio project at same time then slow respond on window. after build process finish pc works normal.

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

#4


-1  

Maintain bulit versions and target version as same

维护bulit版本和目标版本