Use the Android Gradle plugin using the new syntax

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

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

Instead:

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

apply plugin: 'com.android.application'
+6
source share
3 answers

You should put it right after building the script in your gradle application level.

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

buildscript {
    repositories {
       jcenter()
    }

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
}
plugins {
   id "me.tatarka.retrolambda" version "3.7.0"
}
allprojects {
  repositories {
     jcenter()
     maven { url "https://maven.google.com" }

    }
}

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

That should do it.

plugins {
  id "com.android.application" version "<desired version>"
} 

See DSL at https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block

An identifier is what you previously "applied."

0
source

. , Google Gradle.

In build.gradleremove the buildscript block and just add

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

In settings.gradleadd

pluginManagement {
    repositories {
        gradlePluginPortal()
        jcenter()
        google()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "com.android.application") {
                useModule("com.android.tools.build:gradle:${requested.version}")
            }
        }
    }
}
0
source

Source: https://habr.com/ru/post/1673648/


All Articles