My Flutter App is not running after adding cloud_firebase package

Viewed 15265

Recently I have added firebase to my flutter project. To use firebase database services I have added cloud_firebase package. But after adding this package my app is not running and giving me an exception:

BUILD FAILED in 31s
The plugin cloud_firestore requires a higher Android SDK version.
Fix this issue by adding the following to the file C:\Users\Jaguar\Desktop\AppDevelopment\acadmt\android\app\build.gradle:
android {
  defaultConfig {
    minSdkVersion 19
  }
}
Note that your app won't be available to users running Android SDKs below 19.
Alternatively, try to find a version of this plugin that supports these lower versions of the Android SDK.
Exception: Gradle task assembleDebug failed with exit code 1

The exception message is also suggesting following suggestions:

Suggestion: use a compatible library with a minSdk of at most 16,
        or increase this project's minSdk version to at least 19,
        or use tools:overrideLibrary="io.flutter.plugins.firebase.firestore" to force usage (may lead to runtime failures)

I have tried the first two suggestions but still, the app is not working.

7 Answers

It will work after changing the minSdkVersion to 21.

defaultConfig {
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

Previous Answers are also correct. I just used another approach.

  1. First add flutter.compileSdkVersion=21 in local.properties file.

  2. Then add this code in app\build.gradle

def flutterMinSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
if (flutterMinSdkVersion == null) {
    flutterMinSdkVersion = '21'
}

  1. After this make sure minSdkVersion is added to defaultConfig inside app\build.gradle
    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion flutterMinSdkVersion.toInteger()
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true

    }

You may not apply changes after editing minSdkVersion

to solve this problem:

1-open build.gradle file and edit it:

android {
  defaultConfig {
    minSdkVersion 19
  }
}

then on right side of android studio,make sure to select open for editing in android studio to apply changes and syncing gradle for new changes.

2-make a clean (File>invalidate Caches/Restart)

android {
  defaultConfig {
    minSdkVersion 21
    targetSdkVersion 30
  }
}

Result: Running with sound null safety

For the Projects Created After Flutter 2.8 Update

  1. Add this to project_folder/android/local.properties

    flutter.minSdkVersion=21

  2. Now update your project_folder/android/app/build.gradle

    defaultConfig { minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger() }

  3. Run flutter clean && flutter pub get

  4. Rerun app

Reference: Change Android Minsdkversion in Flutter  –  2 Easy Ways [2022]

This problem is happening because a package that you are using is not compatible with the new version of flutter


Side note -> try not to upgrade flutter during working on an old project to avoid these problems

To solve it in flutter version 3.0.5 and after changing minSdkVersion and compileSdkVersion values place, you need to go to this path in your flutter sdk:

"your_flutter_sdk/packages/flutter_tools/gradle/flutter.gradle"

then update: minSdkVersion = 19 , compileSdkVersion = 31

 static int compileSdkVersion = 31 //compile sdk new version
 static int minSdkVersion= 19 //min sdk new version
 static int targetSdkVersion = 31 //target sdk new version = compile sdk version
  • in terminal run flutter clean and flutter pub get then run your application

hope I could help.

Go to this path :

C:\Users\Jaguar\Desktop\AppDevelopment\acadmt\android\app\build.gradle

android {
  defaultConfig {
    minSdkVersion 19
  }
}

change your minSdkVersion to 30

that is:

android {
  defaultConfig {
    minSdkVersion 30
  }
}
Related