Apply Android Gradle plugin using new syntax

gradle apply plugin version
gradle buildscript block
android gradle plugin update
apply plugin: 'com android application
plugin request for plugin already on the classpath must not include a version
gradle plugin example
android custom gradle plugin
gradle buildscript classpath

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'

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}")
            }
        }
    }
}

Using Gradle Plugins, Here's an example, using the old project structure (used in Eclipse) for the main For instance, applying the findbugs plugin will create a new task and make� The default behavior of the plugins {} block is to immediately resolve and apply the plugins. But, you can use the apply false syntax to tell Gradle not to apply the plugin to the current project and then use apply plugin: «plugin id» in the subprojects block or use the plugins {} block in sub projects build scripts:

You should place it right after build script block in your app level gradle file.

// 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
}

Android Gradle plugin release notes, See Example Application for an example of using these settings to enable custom compilation options. Only Use GroovyC. For integration with plain java projects� The com.android.application plugin is necessary in order to setup the Android-specific settings of the build process. Here you can also use com.android.library if you’re creating a library module. The kotlin-android and kotlin-android-extensions plugins allow you to use the Kotlin language and the Kotlin Android extensions in your module.

This should do it.

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

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

The id is what you'd previously "apply".

Gradle Plugin User Guide, Applying a plugin to a project means that allows the plugin to extend the Extend the basic Gradle model (e.g. add new DSL elements that can be In this example, GreetingPlugin is a plain old Groovy object with a field called message. Gradle is working on backporting built-in support for compiling C/C++ code, and the Android plugin will integrate that support when it becomes available. Until then, you can either keep using experimental plugin 0.11.0 with Android Studio 3.0 or later , or migrate to Android Studio's support for using external native build tools .

groovy/groovy-android-gradle-plugin: A Gradle plugin to , A plug-in is included in a build.gradle file with the apply plugin: 'pluginname' statement. For example the entry apply plugin: 'com.android.application' makes This creates a new Gradle based Java project which uses JUnit� Android Gradle plugin 4.2 uses bundletool 1.0.0, which introduces a behavior change for apps using feature modules: Any feature module specified as dist:install-time that's not explicitly marked as dist:removable will become non-removable by default. This new setting optimizes fusing of install-time modules with the base module, potentially

Gradle - Plugins, Use New Relic to detect and instrument all feature modules for Android Instant Apps. Apply the agent plugin in every project Gradle build file. be side- loaded through a Digital Asset Link intent, (for example, mobile.example.com/ signin ). Android Studio 2.2 and higher support building C/C++ components of your Android project with two new options: CMake and ndk-build.Using Android Studio, you can edit and debug your native code while still using either external build system to compile and link the C/C++ sources.

The Gradle build system- Tutorial, Any plugin applications using the legacy apply plugin syntax should be replaced with the newer plugins DSL. This new syntax allows Gradle to� Gradle doesn’t recognize (or knows about) the android block if you use the old apply plugin: 'com.android.application' syntax. There are basically two options to fix that. Either use the new

Comments
  • Is this working on the latest version? I'm getting this error: Unable to load class 'com.android.build.gradle.BaseExtension'.
  • This is not answering the question
  • Error:(3, 0) Plugin [id: 'com.android.application', version: '2.3.0'] was not found in any of the following sources: - Gradle Core Plugins (plugin is not in 'org.gradle' namespace) - Gradle Central Plugin Repository (no 'com.android.application' plugin available - see https://plugins.gradle.org for available plugins)
  • Yep. Doesn't work. I get Error:(10, 0) Plugin 'com.android.application' is already on the script classpath. Plugins on the script classpath cannot be applied in the plugins {} block. Add "apply plugin: 'com.android.application'" to the body of the script to use the plugin.
  • This is incorrect. The plugin ID is not necessarily the same you'd use with apply plugin. Also, as others commented, AFAIK the Android gradle plugin can't yet be applied with the "new" gradle plugin DSL