Android Studio Gradle : Error:Configuration with name 'compile' not found

Viewed 14338

My project refresh is failing with the error for the below gradle script: Error:Configuration with name 'compile' not found.

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

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        classpath 'com.google.gms:google-services:3.1.0'

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

allprojects {
    repositories {
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.google.gms.google-services'
2 Answers

I face the same error, I solved it by removed the .each{...} and move it into bottom dependencies {...} with prefix implementation:

apply plugin: 'com.android.application'

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        google()
        flatDir {
            dirs '<your_aar_directory_patj>'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0-alpha12'
    }

    //[1] Don't put here !!!
}

...

//[2] Remove the below ".each{...}" part, then put it inside dependencies with prefix 'implementation':
/*
fileTree(dir: 'your_aar_directory_path', include: '**/*.aar')
.each { File file ->
dependencies.add("compile",
[name: file.name.lastIndexOf('.').with {
it != -1 ? file.name[0..<it] : file.name
}, ext: 'aar'])
}
*/

dependencies {
    implementation fileTree(dir: '<your_aar_directory_path>', include: '**/*.aar')
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    ...
}

The implementation fileTree(dir: '<your_aar_directory_path>', include: '**/*.aar') suppress the error. The documentation I refer to seems obsolete.

Related