Arish Siddiqui
Arish Siddiqui

Reputation: 61

FAILURE: Build failed with an exception. * Where: Build file 'D:\AProjects\flutter_app\android\app\build.gradle' line: 24

Hey I am trying to compile my flutter project on my real device, but this is the error or issue I am currently facing. Does anyone have a solution for this.

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\AProjects\flutter_app\android\app\build.gradle' line: 24

* What went wrong:
A problem occurred evaluating project ':app'.
> Plugin with id 'com.android.application' not found.

* 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.

I am currently using latest version of flutter. And I am getting this error in my every project. This is what I have in android\app\build.gradle:

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 new 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 plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.flutter_app"
        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 '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

& This is what I have in android\build.gradle :

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

Upvotes: 4

Views: 26248

Answers (3)

yuvan
yuvan

Reputation: 11

I had also face this problem, when i used to change kotlin version in /android/build.gradle to ext.kotlin_version = '1.7.0'

Upvotes: 1

hexhad
hexhad

Reputation: 1303

possible to have some additional {} or other in build.gradle file

in my case, I just missed some } to comment

Upvotes: 0

Huthaifa Muayyad
Huthaifa Muayyad

Reputation: 12373

You mixed up where you have to add apply plugin 'com.android.application'. You added it in the wrong build gradle.

It should go in: 'D:\AProjects\snd_app\android\build.gradle'.

You will most likely have another error arise after fixing this, because of a switch also. Move those from android\build.gradle to android\app\build.gradle.

Upvotes: 3

Related Questions