-1

I tried File -> Invalidate caches\Restart, that didn't help me.

Log:

16:05 Gradle sync started
16:05 Gradle sync failed: Plugin with id 'com.android.application' not found. Consult IDE log for more details (Help | Show Log) (34s 987ms)

build.gradle application

apply plugin: 'com.android.application'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.1"
    defaultConfig {
        applicationId "ru.startandroid.androidlessons"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:27.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Anatoly
  • 3,266
  • 4
  • 17
  • 28

2 Answers2

0

First, any project creates by Android Studio has two separated build.gradle files. That shouldn't cause any problems, for Gradle itself, but Android Studio might not be expecting that.

It's probably a sign that you're continuing to use the new SDK and features, but neglecting to upgrade your build tools along with it. E.g com.android.tools.build:gradle:2.1.2

You should upgrade that Gradle plugin to the latest version

https://developer.android.com/studio/releases/gradle-plugin.html

And upgrade Gradle itself, via the Gradle wrapper or install it externally to Android Studio

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • When I add classpath 'com.android.tools.build:gradle:3.0.1' in my build.gradle file, I get message 'Could not find method classpath() for arguments [com.android.tools.build:gradle:3.0.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.' – Anatoly Dec 07 '17 at 14:07
  • Try reading the link again about upgrading Gradle to version 4.1 or greater, and adding `google()` to the repository section – OneCricketeer Dec 07 '17 at 14:10
  • 1
    I pressed 'sync Gradle' and that helped. this line of code with gradle 4.1.-all.zip was in the file gradle-wrapper.properties. – Anatoly Dec 07 '17 at 14:34
0

your build.graddle in project level should look like below

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

allprojects {
    repositories {
        jcenter()
    }
} 

and gradle-wrapper.properties distributionUrl should be like:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Ergin Ersoy
  • 890
  • 8
  • 28
  • I replaced my build.gradle and I got this message: Cannot invoke method allprojects() on null object – Anatoly Dec 07 '17 at 14:11
  • in your settings graddle did you include application module include ':app' also can you remove buildscript and allprojects from your module build.graddle – Ergin Ersoy Dec 07 '17 at 14:20