chaganiboyy
chaganiboyy

Reputation: 43

Flutter "compileSdkVersion is not specified. Please add it to build.gradle" even though I have added it

I am getting the following error when trying to debug my flutter app on my phone

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring root project 'android'.

compileSdkVersion is not specified. Please add it to build.gradle

My app build. gradle file is as follows:

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 FileNotFoundException("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.wizzcrete"
        minSdkVersion 23
        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 '../..'
}

My android build.gradle file is as follows:

buildscript {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

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

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



apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

I have checked my SDK version and it is indeed 30. I even experimented with using the Android SDK version 29 and updating the compile and target SDK version to 29 in the gradle and that still did not work. My minSDK version is 23 as in order to use firebase in flutter minimum 23 is required. I hope this information is enough to convey the problem, any ideas?

Upvotes: 2

Views: 4164

Answers (1)

chaganiboyy
chaganiboyy

Reputation: 43

SOLVED

The issue was that I did not add all the necessary firebase dependencies to my project level gradle. The plugins I added were in the app level gradle which was wrong, they were supposed to be in the Project level gradle. Additionally, I had to add missing dependencies such as the implementation fo the firebase core bom and the firestore and authentication dependencies to my project level gradle like so:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:28.4.0')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-firestore-ktx'
}

I am adding this answer to help another lost soul like mine was for 6+ hours wracking my brains on this issue. To sum it up: check the dependencies in both your gradle files and make sure you have all of it sorted out.

Upvotes: 1

Related Questions