简体   繁体   English

Gradle 构建(安卓项目)很慢

[英]Gradle build (Android project) is very slow

I have a gradle build that has 32 flavors and builds for 5 hours?我有一个 gradle 构建,它有 32 种口味,构建时间为 5 小时?

Here is my build.gradle这是我的 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 17
    buildToolsVersion "21.1.2"

    dexOptions {
        preDexLibraries false
    }

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 17
        multiDexEnabled true
        versionCode 3
        versionName '3.0.0.0'
    }

    signingConfigs {
        signingConfig1 {
            storeFile file('keystores/signingConfig1.keystore')
            storePassword 'signingConfig1'
            keyAlias 'signingConfig1'
            keyPassword 'signingConfig1'
        }

        ...
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    productFlavors {
        flavor1 {
            applicationId "com.mycompany.project.flavor1"
            signingConfig signingConfigs.signingConfig1
        }

        flavor2 {
            applicationId "com.mycompany.project.flavor2"
            signingConfig signingConfigs.signingConfig2
        }

        ...

        flavor32 {
            applicationId "com.mycompany.project.flavor32"
            signingConfig signingConfigs.signingConfig32
        }
    }

    sourceSets {
        flavor1.res.srcDir 'src-flavors/flavor1/res'
        flavor2.res.srcDir 'src-flavors/flavor2/res'
        ...
        flavor32.res.srcDir 'src-flavors/flavor32/res'
    }
}

dependencies {
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:support-v4:18.0.0'
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile files('libs/stock-chart-full.jar')
    compile files('libs/bcprov-jdk15on-1.47.jar')
    compile files('libs/Pubnub-Android-3.7.2.jar')
    compile 'com.google.android.gms:play-services:7.0.0'
    compile 'org.roboguice:roboguice:3.+'
    provided 'org.roboguice:roboblender:3.+'
    compile 'com.google.code.findbugs:jsr305:1.3.9'
}

My gradle.properties我的 gradle.properties

org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true

What can I do to speed up the build of the application?我该怎么做才能加快应用程序的构建速度? If I build only one flavor for debug|release the build took 3 minutes, if I build all in debug and release it is taking more than 3 hours.如果我只为调试|发布构建一种风格,构建需要 3 分钟,如果我在调试和发布中构建所有版本,则需要 3 个多小时。 Most of the time gradle is spending of the DEX tasks.大多数时间 gradle 是 DEX 任务的花费。

If you're using Android Studio the easiest solution is to go to Preferences -> Gradle and enable Offline Work如果您使用的是 Android Studio,最简单的解决方案是将 go 设置为Preferences -> Gradle并启用Offline Work

This has been around for some time now.这已经存在了一段时间了。

Unfortunately, android studio's make seems to perform a clean every single time, causing the previously DEX'd files to be deleted.不幸的是,android studio 的 make 似乎每次都执行 clean,导致之前的 DEX 文件被删除。

AFAIK you cannot do more than what you already did. AFAIK 你不能做比你已经做过的更多的事情。 It is something Google should work on (regarding the DEX phase).这是谷歌应该努力的事情(关于 DEX 阶段)。

See related: Building and running app via Gradle and Android Studio is slower than via Eclipse参见相关:通过 Gradle 和 Android 构建和运行应用程序 Studio 比通过 Eclipse 慢

EDIT: Jack and Jill are deprecated and are no longer supported!编辑:Jack 和 Jill 已弃用,不再受支持!

Maybe you could try the new experimental android toolchain Jack and Jill: http://tools.android.com/tech-docs/jackandjill也许您可以尝试新的实验性 android 工具链 Jack 和 Jill: http://tools.android.com/tech-docs/jackandjill

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM