简体   繁体   中英

Build failed because of min SDK version on flutter

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

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

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

You need to update following lines in./android/app/build.gradle Example:

android {
   compileSdkVersion flutter.compileSdkVersion <--update this>
   ...
   defaultConfig {
        minSdkVersion flutter.minSdkVersion  <-- this>
        targetSdkVersion flutter.targetSdkVersion  <-- this>
    }

}

some of your flutter packages may give errors so update them to latest version or ask the package provider to release latest version accordingly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM