使用android gradle插件3.0.0比gradle插件2.3.3慢

问题描述 投票:0回答:1

当将com.android.tools.build:gradle:2.2.3更新为com.android.tools.build:gradle:3.0.0时,我发现构建时间超过2.3.3。

build.gradle

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}

app/build.gradle在这里,我所有的依赖都使用compile

apply plugin: 'com.android.application'
android {
    sourceSets {
        main {
            ...
        }
    }

    dexOptions {
        preDexLibraries = false
        incremental true
        javaMaxHeapSize "8g"
        keepRuntimeAnnotatedClasses false

    }

    lintOptions {
        abortOnError false
        checkReleaseBuilds false
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'org/apache/commons/codec/language/bm/*.txt'
    }
    compileSdkVersion 24
    buildToolsVersion "27.0.1"
 }
 defaultConfig {
        applicationId "com.gg.kk"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 512654
        versionName "version"
        multiDexEnabled true

}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:multidex:1.0.1'
    .... many dependencies ....
}

谁能告诉我为什么我的构建变得缓慢?

gradle plugins
1个回答
0
投票

许多不同的东西都会影响gradle构建时间。

要减少此时间,您可能需要至少尝试以下解决方案之一:

  • 检查Gradle Deamon是否已启用。它应该默认启用。
  • 让你的Gradle保持最新(你已经很擅长)你可以去/gradle/wrapper/gradle-wrapper.properties并通过更改distributionUrl来升级gradle版本
  • 增加你的堆大小 org.gradle.jvmargs = -Xmx3072m -XX:MaxPermSize = 512m -XX:+ HeapDumpOnOutOfMemoryError -Dfile.encoding = UTF-8
  • 通过添加gradle.propertiesorg.gradle.parallel=true中启用并行性
  • 不要使用编译'com.android.support:appcompat-v7:27.+'等动态依赖项
  • File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle检查'Offline work' 'Global Gradle settings'短期解决方案。
  • 检查这个https://developer.android.com/studio/build/optimize-your-build.html
© www.soinside.com 2019 - 2024. All rights reserved.