Martin Holmén
Martin Holmén

Reputation: 9

A problem occurred configuring root project 'android'. > : compileSdkVersion is not specified. Please add it to build.gradle

I am trying with help of chatGPT to compile my flutter/android build in Visual Studio Code. It worked before and now it does not.

This is my app/build.gradle

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "com.google.gms.google-services"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

dependencies {
    // Import the Firebase BoM
    implementation platform('com.google.firebase:firebase-bom:33.9.0')

    // Add required Firebase dependencies here
    implementation 'com.google.firebase:firebase-messaging'
}

android {
    compileSdk 35 //rootProject.ext.compileSdkVersion
    namespace = "com.example.kommunappen"
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17
    }

    defaultConfig {
        applicationId "com.example.kommunappen"
        minSdk 28//rootProject.ext.minSdkVersion
        targetSdk 35 //rootProject.ext.targetSdkVersion
        versionCode flutter.versionCode
        versionName flutter.versionName
    }

    println("compileSdkVersion: " + android.compileSdkVersion)

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source = "../.."
}

This is my android/build.gradle

plugins {
    id 'com.android.application' 
    id "kotlin-android"
    id 'com.google.gms.google-services' version '4.4.2' apply true
}

ext {
    kotlin_version = '1.8.20'
    compileSdkVersion = 35
    targetSdk = 35
    minSdk = 28
    appCompatVersion = "1.6.1"
    playServicesLocationVersion = "21.3.0"
    hmsLocationVersion = "6.12.0.300"
    removeBackgroundGeolocationDebugSoundsInRelease = false
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "${project(':flutter_background_geolocation').projectDir}/libs" }
        maven { url 'https://developer.huawei.com/repo/' }
        maven { url "${project(':background_fetch').projectDir}/libs" }
        jcenter()
    }
}

println("DEBUG: compileSdkVersion from ext is: " + ext.compileSdkVersion)

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

My println gives DEBUG: compileSdkVersion from ext is: 35 compileSdkVersion: android-35

Still I get the error: A problem occurred configuring root project 'android'.

com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

I tried to build my Android project and expected it to work. Instead it throws this error and I cannot figure out what is wrong.

Upvotes: 0

Views: 47

Answers (2)

Nnamani Daniel
Nnamani Daniel

Reputation: 81

In the Android/build.gradle, remove everything before allprojects{

Upvotes: 0

tyczj
tyczj

Reputation: 73996

Your compileSdkVersion = 35 means nothing and is not what it is asking for. You need to replace compileSdk in your apps build.gradle with compileSdkVersion

Upvotes: 0

Related Questions