Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply Android Gradle plugin using new syntax

How can I apply Android plugin using new Gradle plugin syntax:

plugins {
    id "..." version "..."
}

Instead of:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}

apply plugin: 'com.android.application'
like image 338
Maxim Pestryakov Avatar asked Mar 30 '17 21:03

Maxim Pestryakov


People also ask

How do I add plugins to Gradle?

To add a Gradle plugin with dependencies, you can use code similar to the following: Plugin DSL GA versions. Plugin DSL non GA versions. Legacy Plugin Application.

How do I update my Kotlin Gradle plugin?

Select Tools | Kotlin | Configure Kotlin Plugin Updates. In the Update channel list, select the Early Access Preview channel. Click Check again. The latest EAP build version appears.


1 Answers

I just ran into the same problem and found the solution here. The problem results from the fact that Google for whatever reasons decided to put the application plugin not into Gradle's repository of community plugins.

In build.gradle remove the buildscript block completely and just add

plugins {
    id 'com.android.application' version '3.4.0'
}

In settings.gradle add

pluginManagement {
    repositories {
        gradlePluginPortal()
        jcenter()
        google()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "com.android.application") {
                useModule("com.android.tools.build:gradle:${requested.version}")
            }
        }
    }
}
like image 76
Nantoka Avatar answered Sep 24 '22 19:09

Nantoka