0

What is causing the following build exception in an existing Flutter project after upgrading flutter to 2.10?

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\Blah\.gradle\caches\transforms-2\files-2.1\602ce26881e3b92788ae83c190d3c36f\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\Blah\.gradle\caches\transforms-2\files-2.1\9520e6f13992d2f4d96b17b856330597\jetified-window-1.0.0-beta04\META-INF\com\android\build\gradle\aar-metadata.properties.
Baker
  • 24,730
  • 11
  • 100
  • 106

3 Answers3

2

Flutter 2.10 support for Foldable devices via AndroidX

Flutter 2.10 added support for foldable Android devices.

This relies on Android SDK API version 31's AndroidX library dependency of: androidx.window:window-java:1.0.0

The build failed because:

  1. this new AndroidX dependency requires Android compileSdkVersion of 31 or higher.

  2. It also requires kotlin_version of 1.5.31 or higher.

So existing Flutter/Android projects may need some gradle file changes:

android/build.gradle:

  • bump ext.kotlin_version to at least 1.5.31 (1.6.10 is available as of Feb 2022)
buildscript {
    ext.kotlin_version = '1.5.31'

android/app/build.gradle

  • bump compileSdkVersion to 31 or higher
android {
    compileSdkVersion 31

If you don't have Android 12 SDK (API level 31) installed...

Install & Use SDK API 31 (Android 12) in Android Studio

In Android Studio

  • go to Tools > SDK Manager > tick/check Android 12 (S) API Level 31 > click OK button > wait for download/install

Android Studio install SDK 31

Platform & Project Settings

Next we need to add Android SDK API 31 to our Project Structure under both Platform Settings and Project Settings

  • Android Studio > File > Project Structure
  • Under Platform Settings click SDKs
  • In the middle column click + icon button, select "Add Android SDK.."
  • You will be prompted to select an Android SDK directory
    • Select your Android Sdk root directory like C:\Android\Sdk
    • do not select the specific API version like C:\Android\Sdk\platforms\android-31. This will be rejected.

Add SDK to Platform Settings

  • A "Create New Android SDK" window will pop up.
  • By default Java SDK 11 & Build target: Android API 31 will be preselected. If not, select them.
  • Click OK.

Select Build Target

  • Android API 31 Platform is now available for your Project.
  • Now under Project Settings, click on Project

Platforms available

  • On the right under Project SDK:
  • Click the dropdown list
  • Select Android API 31 Platform
  • Click OK

Select API 31 Platform

  • We're done.

Android 12 SDK API 31 is now installed and ready to compile this project.

Baker
  • 24,730
  • 11
  • 100
  • 106
  • Sorry, this did not work for me. I wonder why the upgrade to flutter 2.10 is not working no matter what i tried. – defemz Mar 12 '22 at 05:22
0

You should Set both compileSdkVersion and targetSdkVersion to 31 in your build.gradle(app) file.

android {
    compileSdkVersion 31 // <-- This
    defaultConfig {
        applicationId "com.example.app"
        targetSdkVersion 31 // <-- and this too
        // ...
    }
}
My Car
  • 4,198
  • 5
  • 17
  • 50
  • There is no hard requirement that `targetSdkVersion` be equal to `compileSdkVersion` and it will not solve the issue in the original question. Target SDK specifies general behavior for apps dictated by that API level. Compile SDK specifies which platform interfaces are available for an application to call. See [this answer](https://stackoverflow.com/a/47269079/2301224) for more details. – Baker Feb 26 '22 at 21:29
0

I hade the same issue, all those listed above did not for me, what worked for me is that i downgrade the geolocator from 9.0.1 to 7.7.0