androidflutterandroid-sdk-toolsmobile-development

MinSdk error when adding an Android App Widget in Flutter Android Studio


Running on:

  1. Flutter 3.24.5
  2. Dart 3.5.4
  3. No issues in flutter doctor

Problem: I am trying to create a Flutter project which should contain a home screen widget. I am stuck on the step of adding a widget in the /android/app/ folder of my project as seen in the image below: Steps to add a widget

My thoughts and attempts: The error suggests my minSdk version is <16. I tried the following fixes, but none worked:

  1. Manually set the minSdk parameter in /android/app/build.gradle to 21, but nothing changed.
  2. Verify the flutter installation files at flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy , but since I am running on Flutter 3.x, the minSdkVersion was already set to 21:
public final int minSdkVersion = 21
  1. Invalidate Caches... in Android Studio, by going to Files -> Invalidate Caches... -> Invalidate and Restart, but nothing changed
  2. Ran ./gradlew clean and then ./gradlew build in the android/ folder, but nothing changed.
  3. Tried everything I could for Flutter 3.x in the already answered StackOverflow thread: Flutter : How to change Android minSdkVersion in Flutter Project?, but nothing changed.

Whatever I try, I always get the "Project not ready" error. I can't find what I am missing. Thank you for your input.


Solution

  • I had the same problem and finally I got the solution.
    First Update your Android Studio (For me is 2024.3.1 Patch 1 Version). Then do these steps:

    1. Click on File and the click Open

    2. Choose android folder under your project route

    3. Click OK and wait for Andriod Studio to sync

    4. Click on Sync Project with Gradle Files (Ctrl + Shift + O)

    Now, you can right click on app -> New -> Widget -> App Widget

    Thats it.

    Hope it help you. Good Luck.