"Failed to apply plugin 'com.android.internal.application"

Viewed 10981

I'm using flutter on android studio for the first time and after installing it I kept getting this error my Gradle files version is 4.1.0

Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\ahmed\flutter12\android\app\build.gradle' line: 24

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
   > Could not create plugin of type 'AppPlugin'.
      > Could not generate a decorated class for type AppPlugin.
         > com/google/wireless/android/sdk/stats/GradleBuildProject$PluginType

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
Exception: Gradle task assembleDebug failed with exit code 1

and my android version is 4.0.1

this is my build.gradle files I don't know what's went wrong I updated my jdk sdk and android studio to the last version 4.1.2

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
   localPropertiesFile.withReader('UTF-8') { reader ->
       localProperties.load(reader)
   }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
   throw  GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
   flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
   flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
   compileSdkVersion 30

   defaultConfig {
       // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
       applicationId "com.example.flutterwq"
       minSdkVersion 16
       targetSdkVersion 30
       versionCode flutterVersionCode.toInteger()
       versionName flutterVersionName
   }

   buildTypes {
       release {
           // TODO: Add your own signing config for the release build.
           // Signing with the debug keys for now, so `flutter run --release` works.
           signingConfig signingConfigs.debug
       }
   }
}

flutter {
   source '../..'
}
2 Answers

Open the android/build.gradle file, and check the version of com.android.tools.build:gradle :

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

Make that version smaller, until some version works. The version can be choosed from here, in the plugin column: https://developer.android.com/studio/releases/gradle-plugin#updating-gradle

The problem occurs when gradle is too old and android gradle plugin is too new.

Try these steps. Open the Gradle Scripts/gradle-wrapper.properties file.

Replace the existing version with '6.7-all.zip':

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

Then in the build.gradle file, first replace the version in classpath to 4.1.0, then replace 'jcenter()' with 'mavenCentral()':

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

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}
Related