android – 即时运行比标准版本更长

现在已经有一段时间了,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'

解决方法

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

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

-xms256m
    -Xmx1280m
-XX:MaxPermSize=350m

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...