./Gradlew Build需要2小时40分钟 - 还有改进的余地吗?

时间:2017-05-16 20:38:26

标签: android performance gradle android-gradle build.gradle

我们正在处理的应用程序不是很大 - 大多数是从各个端点(服务器端)填充的空应用程序,但我们目前有18种不同版本的应用程序可以构建。

问题是,应用程序将构建78种风格,如果构建时间是线性的,我们会根据./gradlew build请求查看大约11个小时。

我根本不熟悉Gradle,我希望你们能帮助我找到一些可能会改善我们的构建时间的问题区域

这是build.gradle:

apply plugin: 'com.android.application'

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

apply plugin: 'io.fabric'
apply from: '../jacoco.gradle'
apply from: '../flavors.gradle'
apply from: '../autoTasks.gradle'

ext {
    applicationName = 'OurApp'
    supportLibVersion = '25.3.0'
    playServicesVersion = '9.6.1'
}

android {
signingConfigs {
    debug {
        keyAlias 'key'
        keyPassword 'pass'
        storeFile file('../file.keystore')
        storePassword 'pass'
    }
    release {
        keyAlias 'key'
        keyPassword 'pass'
        storeFile file('../file.jks')
        storePassword 'pass'
    }
}

compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 25
    vectorDrawables.useSupportLibrary true
    testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    multiDexEnabled true
}

dataBinding {
    enabled true
}

lintOptions {
    abortOnError false
}

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release

        buildConfigField 'String', 'DFP_NETWORK_ID', '"id"'
        buildConfigField 'String', 'YOUTUBE_API_KEY', '"ourkey"'
    }
    debug {
        signingConfig signingConfigs.debug
        testCoverageEnabled = true

        buildConfigField 'String', 'DFP_NETWORK_ID', '"id"'
        buildConfigField 'String', 'YOUTUBE_API_KEY', '"anotherKey"'
    }
    debuggable.initWith(buildTypes.debug)
    debuggable {
        testCoverageEnabled = false
    }
}

dexOptions {
    javaMaxHeapSize "4g"
}

applicationVariants.all { variant ->
    if (variant.buildType.name == 'release') {
        createZipProguardTask(variant);
    }

    updateApkName(variant);
    }
}

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

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

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

annotationProcessor 'com.bluelinelabs:logansquare-compiler:1.3.7'
annotationProcessor 'com.squareup:javapoet:1.8.0'
annotationProcessor 'com.google.dagger:dagger-compiler:2.7'

compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
compile "com.android.support:support-v13:${supportLibVersion}"
compile "com.android.support:percent:${supportLibVersion}"
compile "com.android.support:preference-v14:${supportLibVersion}"
compile "com.google.android.gms:play-services-gcm:${playServicesVersion}"
compile "com.google.android.gms:play-services-maps:${playServicesVersion}"
compile "com.google.firebase:firebase-core:${playServicesVersion}"
compile "com.google.firebase:firebase-messaging:${playServicesVersion}"

compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.roughike:bottom-bar:2.2.0'

compile 'io.reactivex.rxjava2:rxjava:2.0.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.l4digital.rxloader:rxloader:2.0.1'

compile 'com.bluelinelabs:logansquare:1.3.7'
compile 'com.github.aurae.retrofit2:converter-logansquare:1.4.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'

compile 'com.google.dagger:dagger:2.7'

compile 'com.facebook.stetho:stetho:1.4.2'
compile 'com.facebook.stetho:stetho-okhttp3:1.4.2'

compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
    transitive = true
}
compile(name:'googlemediaframework-release', ext:'aar')
compile "com.google.android.gms:play-services-ads:${playServicesVersion}"
compile "com.google.android.gms:play-services-analytics:${playServicesVersion}"
compile 'com.flurry.android:ads:6.2.0'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
compile 'com.google.android.exoplayer:exoplayer:r1.5.14'

compile 'com.android.support:multidex:1.0.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.5.0'

debugCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
debuggableCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'

androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.squareup.okhttp3:okhttp:3.5.0'
androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile('com.android.support.test:rules:0.5') {
    exclude module: 'support-annotations'
}
androidTestCompile (name:'cloudtestingscreenshotter_lib', ext:'aar')

androidTestCompile('com.android.support.test:runner:0.5') {
    exclude module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2') {
    exclude module: 'support-annotations'
}

compile(name:'MapSDK', ext:'aar')
compile('com.twitter.sdk.android:twitter:2.3.2@aar') {
    transitive = true;
}
}

def createZipProguardTask(variant) {
    def prefix = project.ext.applicationName;

    if (project.hasProperty('buildNumber')) {
        prefix += '-' + project.getProperties().get('buildNumber');
    }

    def taskName = variant.flavorName.substring(0, 1).toUpperCase() + variant.flavorName.substring(1);

    task("zipProguard${taskName}", type: Zip) {
        archiveName = "${prefix}-${variant.flavorName}-proguard.zip";

        from "build/outputs/mapping/${variant.flavorName}/release"
        destinationDir file('build/outputs/mapping')
    }
}

def updateApkName(variant) {
    def prefix = project.ext.applicationName;

    if (project.hasProperty('buildNumber')) {
        prefix += '-' + project.getProperties().get('buildNumber');
    }

    variant.outputs.each { output ->
        def fileName = output.outputFile.name.replace('app', prefix);
        def outputFile = new File(output.outputFile.parent.toString(), fileName.toString());

        output.outputFile = outputFile;
    }
}

以下是我们在gradle属性中的含义:

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

任何意见都会非常感激 - 就像我说的那样,我根本不熟悉gradle,所以我对任何事都持开放态度。

提前谢谢

1 个答案:

答案 0 :(得分:0)

我确定你现在想出了什么,但仅限未来的googlers -

Android Studio gradle takes too long to build大大提高了我的gradle构建速度。

它建议在Android Studio中启用离线工作,方法是转到文件>设置>构建,执行,部署> gradle并检查& #34;离线工作"选项。