0

I'm currently working on creating my own Gradle custom distribution and I want to add some default settings to all my Android projects. I tried to do this with the following init script:

initscript {
    repositories {
      mavenCentral()
      google()
    }
    
    dependencies {
      classpath "com.android.tools.build:gradle:7.1.1"
    }
}

apply plugin: 'com.android.application'

gradle.allprojects {
    android {
        ...
    }

    dependencies {
        implementation 'junit:junit:4.12'
    }
}

but with this I get Plugin with id 'com.android.application' not found. What am I missing here?

Cilenco
  • 6,951
  • 17
  • 72
  • 152
  • 1
    I think you need to move `apply plugin: `com.android.application` inside the `allprojects` block. You might also need to add put your configuration blocks (android and dependencies) into a `afterEvaluate { }` block – romtsn Mar 16 '22 at 18:47

3 Answers3

4

For gradle init script, you must use the fully qualified class name of the plugin instead of the id. So you will have to apply the plugin this way:

apply plugin: com.android.build.gradle.AppPlugin
Huu Phuong Vu
  • 959
  • 3
  • 10
0

Make sure your Gradle version is compatible with your Android Gradle Plugin.

For more information you can follow the link below, if it helps you plugin with id com.android.application not found

-1

Change the initscript to buildscript.


And also, does this build.gradle in root project/directy? Because you Android Gradle Plugin is applied in the gradle module not in the root.

So apply:

apply plugin: "com.android.application"

inside your module's build.gradle.

Jimly Asshiddiqy
  • 335
  • 4
  • 15