minCompileSDK specified in dependency AAR metadata (androidx.window:window:1.0.0-beta04)

Issue

I’m currently using Android studio attempting to run an old Flutter project I made about a year and a half ago. When I attempt to run it I get the error:

The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) 
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.window:window-java:1.0.0-beta04.\

The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.window:window:1.0.0-beta04.

I am aware of similar questions having been asked and answered, but there is a key difference. The answer to these questions is to force gradle to use an older version of the package, yet as far as I have been able to figure out 1.0.0 is the lowest version of these dependencies.

I thought I could perhaps just remove the dependencies, but I’m not sure if I need them or how to even do that, but I cannot use an older version.

Currently my minSdkVersion is 21 and my targetSdkVersion as well as compileSdkVersion is 30. I tried just raising these numbers to 31 and 32, but that brought other issues up that I was not able to solve.

What are my options here? Can I remove the packages somehow? Should I upgrade to SDK 31 somehow?

UPDATE:

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

android {
    compileSdkVersion 30

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

    defaultConfig {
        applicationId "com.example.r_app"
        minSdkVersion 21
        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 platform('com.google.firebase:firebase-bom:28.0.1')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

My build.gradle file as per @romtsn ‘s request.

Additionally I tried changing my SDK to a bunch of different options ranging from 30-32 in the Android Studio SDK manager, but to no avail.

Solution

replace this code:

android {
    compileSdkVersion 30

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

    defaultConfig {
        applicationId "com.example.r_app"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
...........

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

by the following

android {
    compileSdkVersion 31

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

    defaultConfig {
        applicationId "com.example.r_app"
        minSdkVersion 21
        targetSdkVersion 31
        multiDexEnabled true
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

.......and.......
dependencies {
    implementation platform('com.google.firebase:firebase-bom:28.0.1')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.guava:guava:27.0.1-android'
}

and add the line classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" in project_file -> android -> build.gradle :

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

After that open for editing in Android Studio on the top right.. Allow it to build. then Run. If required – flutter clean – pub_get in pubspec.yaml. I think this should work.. Because I am not sure what other requirements or errors you are getting.

Answered By – GOKU

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published