从Android Studio构建Windows在设备上启动速度比从Android Studio Mac OS构建的速度慢

时间:2016-07-03 10:11:55

标签: android windows android-studio android-gradle

我有一个Android项目,直到几个星期前我在它上面制作了一个macbook。在Android Studio将它们安装到设备上之后,构建立即开始。

在我转移到运行相同版本的Android Studio和JDK 8的新Windows笔记本电脑后,我注意到构建开始慢得多。我的意思是,在AS安装并运行应用程序后,应用程序在第一个活动运行后平均保持在白色屏幕上大约4-5秒(最多15-20秒)。

视频:

在Mac OS上构建:https://youtu.be/H55mfxOoBbM

在Windows上构建:https://youtu.be/-7FphwiMvs8

感觉就像您在调试模式下运行并且它正在等待调试过程附加。我不记得我是否在mac上更改了Android Studio中的设置,因为我已经将配置移植了3年以上。

我该怎么做才能解决这个问题?

编辑:我的猜测是windows bulid会触发jit编译器。

Android Studio 2.1.2

Java 1.8 u91

项目gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

构建gradle文件:

 /*
 * Gets the version name from the latest Git tag
 */

def getVersionName = { ->
    def stdout = new ByteArrayOutputStream()
    def command = 'git'

    if (System.properties['os.name'].toLowerCase().contains('windows')) {
        command = 'C:/Program Files/Git/cmd/git.exe'
    }

    exec {
        commandLine command, 'describe', '--tags'
        standardOutput = stdout
    }
    return stdout.toString().trim()
}

project.ext.versionPropsFile = file('version.properties')

def getBuildNumber() {
    def Properties versionProps = new Properties()
    versionProps.load(new FileInputStream(project.versionPropsFile))
    def buildNumber = versionProps['artifactBuildNumber'].toInteger() + 1
    versionProps['artifactBuildNumber'] = buildNumber.toString()
    versionProps.store(versionPropsFile.newWriter(), null)
    return buildNumber
}

def getReleaseVersionCode() {
    def Properties versionProps = new Properties()
    versionProps.load(new FileInputStream(project.versionPropsFile))
    def code = versionProps['artifactReleaseVersionCode'].toInteger()
    return code
}

def getDevVersionCode() {
    def Properties versionProps = new Properties()
    versionProps.load(new FileInputStream(project.versionPropsFile))
    def code = versionProps['artifactDebugVersionCode'].toInteger()
    return code
}

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "com.senic.nuimoapp"
        minSdkVersion 18
        targetSdkVersion 23
        versionName getVersionName()
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix "-" + getBuildNumber() + "-DEBUG"
        }
    }
    productFlavors {
        dev {
            versionCode getDevVersionCode()
        }
        prod {
            versionCode getReleaseVersionCode()
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/beans.xml'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
    compile 'com.android.support:support-v4:24.0.0'
    compile 'com.android.support:recyclerview-v7:24.0.0'
    compile 'com.google.android.gms:play-services-appindexing:9.2.0'
    // View binder
    compile 'com.jakewharton:butterknife:7.0.1'
    // DB and ORM
    compile 'com.j256.ormlite:ormlite-core:4.48'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    // Json parser
    compile 'org.immutables:gson:2.1.14'
    // Nuimo sdk
    compile 'com.senic:nuimo-android:0.5.1'
    compile 'org.jetbrains.kotlin:kotlin-stdlib:1.0.0'
//    compile project(':..:nuimo-android:nuimo')
    // Bug tracker
    compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') {
        transitive = true;
    }
    testCompile 'junit:junit:4.12'
    // LIFX Lan SDK
    compile 'com.github.getsenic:lifx-sdk-android:0.5.11@aar'
    // Philips Hue SDK
    compile files('libs/huelocalsdk.jar')
    compile files('libs/huesdkresources.jar')
    // OTA firmware update library
    compile 'no.nordicsemi.android:dfu:0.6.3'
    // Rest helper library
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    // Upnp Library for Sonos or Raumfeld
    compile files('libs/cling-core-2.1.0.jar')
    compile files('libs/cling-support-2.1.0.jar')
    compile files('libs/seamless-http-1.1.1.jar')
    compile files('libs/seamless-util-1.1.1.jar')
    compile files('libs/seamless-xml-1.1.1.jar')
    compile 'org.eclipse.jetty:jetty-server:8.1.19.v20160209'
    compile 'org.eclipse.jetty:jetty-client:8.1.19.v20160209'
    compile 'org.eclipse.jetty:jetty-servlet:8.1.19.v20160209'
    compile 'org.slf4j:slf4j-jdk14:1.7.20'
    // Custom color picker (for Lifx and Philips Hue)
    compile 'com.larswerkman:HoloColorPicker:1.5'
}

1 个答案:

答案 0 :(得分:0)

根据此主题中的第一个答案:https://code.google.com/p/android/issues/detail?id=215000#c1

罪魁祸首是...... 即时运行。禁用它,它和以前一样快。