Gradle is taking a long time to build

2019-08-21 02:19发布

问题:

All of a sudden my gradle build has become really really slow seams like its doing some extra work that it didn't used to do here is a picture from build :

as you can see there are a lot of tasks here it used to be build in like 10 seconds now it takes minutes to build whats wrong with it? it writes things in the bottom bar like resolving some libraries for kotlin and doing something related to caching "variant attribute matching cache" here is the picture : i was trying to activate the annotation processor that it happend here is my gradle codes:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.example.moein.volley_download_kotlin"
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner     "android.support.test.runner.AndroidJUnitRunner"
    javaCompileOptions{
        annotationProcessorOptions {
            includeCompileClasspath true
        }
    }
 }
 buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),     'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-             core:3.0.2'

implementation 'com.tonyodev.fetch2downloaders:fetch2downloaders:2.0.0-RC21'
implementation 'com.android.volley:volley:1.1.0'

implementation 'com.google.dagger:dagger:2.13'
annotationProcessor 'com.google.dagger:dagger-compiler:2.13'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.13'
}

and the other code

buildscript {
ext.kotlin_version = '1.2.30'
repositories {
    google()
    jcenter()
 }
 dependencies {
    classpath 'com.android.tools.build:gradle:3.1.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

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

  allprojects {
  repositories {
    google()
    jcenter()
  }
  }

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

回答1:

  • In gradle setting check work offline.
  • Clean and rebuild your project.
  • In gradle.properties in Gradle scripts directory(i.e., ~/.gradle/gradle.properties), add

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

This settings have helped me a lot.