Home > Blockchain >  Build failed because of min SDK version on flutter
Build failed because of min SDK version on flutter

Time:01-03

I have ran flutter upgrade on my app and now when I try to run flutter run I get this error doing the gradle build phase.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Multiple task action failures occurred:
   > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
      > 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.
        AAR metadata file: C:\Users\jp_ku\.gradle\caches\transforms-2\files-2.1\625039eaad011f884ddd84f857a44b7f\jetified-window-java-1.0.0-beta04\META-INF\com\android\build\gradle\aar-metadata.properties.
   > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
      > 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.
        AAR metadata file: C:\Users\jp_ku\.gradle\caches\transforms-2\files-2.1\a78fdf90e4c1f8464b19895cfb365f3f\jetified-window-1.0.0-beta04\META-INF\com\android\build\gradle\aar-metadata.properties.

* 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 13s
Exception: Gradle task assembleDebug failed with exit code 1

This are my dependencies on pubspec.yaml :

version: 2.1.0

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  intl: ^0.17.0
  sqflite: ^2.0.0 3
  provider: ^5.0.0
  linked_scroll_controller: ^0.2.0
  flutter_neumorphic: ^3.1.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_launcher_icons: "^0.9.1"

flutter_icons:
  android: "launcher_icon"
  ios: false
  image_path: "assets/icon/icon.png"

How can I fix this issue? I've tried changing the compileSdkVersion on gradle but then it just gives me another error :

C:/Users/jp_ku/.gradle/caches/transforms-2/files-2.1/cdd51607f1d98bcc689bce197d763afe/jetified-kotlin-stdlib-jdk8-1.5.30.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.```

CodePudding user response:

You need to update your minimum SDK in ./android/app/build.gradle Example:

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.projectname"
    minSdkVersion 31 //*** This is the part that needs to be changed, previously was 30
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Reference: How to change Android minSdkVersion in flutter project

CodePudding user response:

You need to change kotlin version in ./android/build.gradle

Example:

buildscript {
    ext.kotlin_version = '1.5.1' //change 1.5.1 to 1.1.15
  • Related