Flutter : How to change Android minSdkVersion in Flutter Project? - android

I was trying to start a flutter project for an App using bluetooth to communicate. For that, I was using flutter blue.
Unfortunately, when trying to run (on an Android device) the first example I created I was met with the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:flutter_blue] /home/maldus/Projects/flutter/polmac/build/flutter_blue/intermediates/manifests/full/debug/AndroidManifest.xml as the library might be using APIs not available in 16
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="com.pauldemarco.flutterblue" to force usage (may lead to runtime failures)
If I were on Android Studio, I'd know how to bump up the Android minSdkVersion, but on a flutter project (using VSCode) I was a little lost.
Is it possible to increase the minSdkVersion with flutter, and how?

It is indeed possible to increase minSdkVersion, but it took me way too much time to find it out because google searches mostly yields as result discussions about the absolute minimum Sdk version flutter should be able to support, not how to increase it in your own project.
Like in an Android Studio project, you have to edit the build.gradle file. In a flutter project, it is found at the path ./android/app/build.gradle.
The parameter that needs to be changed is, of course, minSdkVersion 16, bumping it up to what you need (in this case 19).
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.projectname"
minSdkVersion 19 //*** This is the part that needs to be changed, previously was 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Seems obvious now, but took me long enough to figure it out on my own.

Flutter 2.8 or Later
build.gradle update
Before Updating to Flutter 2.8
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.example.app"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
After updating to Flutter 2.8:
android {
compileSdkVersion flutter.compileSdkVersion
defaultConfig {
applicationId "com.example.app"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
You should change from local.properties following instruction:
First go to the android->local.properties
And changes from here
Change like this from build.gradle
android {
compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()
defaultConfig {
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

If you didn't know, Google Playstore only allows minSdkVersion to be 20 or above. But flutter has still set default minSdkVersion to 16. Can you see that you'll be always obliged to manually change for each new project?
All your suggestions above are good, but they are not the best, because you will be forced to temper with the build.gradle for each new project you create.
The best way is to modify the value of the global minSdkVersion variable from its source, so all projects, new or old, will adopt it. Remember flutter.minSdkVersion means that the variable is in flutter directory (with the sdk).
The file in question is flutter.gradle.
the address is flutter-directory/packages/flutter_tools/gradle/flutter.gradle
class FlutterExtension {
/** Sets the compileSdkVersion used by default in Flutter app projects. */
static int compileSdkVersion = 31
/** Sets the minSdkVersion used by default in Flutter app projects. */
static int minSdkVersion = 16
/** Sets the targetSdkVersion used by default in Flutter app projects. */
static int targetSdkVersion = 31
change the value of the minSdkVersion from 16 to 20 or above, and do not disturb the code in build.gradle.
If you want, you can watch a video I made on Youtube, explaining it under: flutter configure minSdkVersion from 16 to 20 or above

For flutter v2.8
Inside local.properties add
sdk.dir='<path>'
flutter.sdk='<path>'
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=21
flutter.targetSdkVersion=30
flutter.compileSdkVersion=30
app-level build.gradle
defaultConfig {
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Now you can use localProperties.getProperty() to read the value from the properties file.

You can change the minSdkVersion in the file Project_Name/android/app/build.gradle , defaultconfig :
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.projectname"
minSdkVersion 16 // <--- There
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

With the new Flutter projects (2.8.0), with the 'Flutter style', you able to change minimum sdk version in local.properties (instead of editing app/build.gradle file).
# android/local.properties
flutter.minSdkVersion=19
Look in android/app/build.gradle file, you'll see the variable constraint like this:
# android/app/build.gradle
android {
defaultConfig {
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}

Here the detailed solution for changing MinSdk /Minsdk version error, follow the steps.
Add following lines on android\local.properties
sdk.dir=
flutter.sdk=C:\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=21
flutter.targetSdkVersion=31
flutter.compileSdkVersion=31
Delete existing lines and paste it on app level build.gradle: android\app\build.gradle
defaultConfig {
applicationId "app-id"
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

Add the following lines to android/local.properties file:
flutter.versionCode=1
flutter.versionName=0.0.1
flutter.flutterMinSdkVersion=24
flutter.flutterTargetSdkVersion=31
Add the following lines at the top-level in the file may be after "def versionName =" in the file android/app/build.gradle:
def flutterMinSdkVersion = localProperties.getProperty('flutter.flutterMinSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = '16'
}
def flutterTargetSdkVersion = localProperties.getProperty('flutter.flutterTargetSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = '31'
}
finally edit the section of the build.gradle that match as follows:
defaultConfig {
applicationId "do.main.subdomain" // Use your App ID
minSdkVersion flutterMinSdkVersion.toInteger()
targetSdkVersion flutterTargetSdkVersion.toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Once all this is done you are good to go. Next time you want to update something you only have to change one file.

All answers are best. But the following way is best in changing SdkVersion after Flutter 2.8 :
Go to your root directory where flutter is installed. It should be like
C:\src\flutter\flutter
Then go to
packages>Flutter tools>gradle>
In Gradle, you will see many files, locate flutter.gradle . Right-click on it and edit it with text editor/notepad.
here you will find all SDK versions. Change them, save, and then you are ready to go
the complete path should be like this: (in my case)
C:\src\flutter\flutter\packages\flutter_tools\gradle

Follow these steps to change the minSdkVersion problem.
First=> YouProject_name/android/app/build.gradle
Second=> defaultconfig { //you can find it inside build.gradle }
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.umair.product_details_using_crud"
minSdkVersion 16 // here you can change minSdkVersison
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

I found the best way to fix this so it performs globally across all of your future apps as well is by changing the setting in the flutter.gradle file located in your default build section. If you're using VSCode
go to this location (or the location you've installed flutter)
C:\src\flutter\packages\flutter_tools\gradle\
drag the flutter.gradle file into VSCode
update the min, compile, and/or target versions
save

This is how I approached when I got this issue recently:
Inside <your-project>/android/app/build.gradle
Find android -> defaultConfig -> minSdkVersion and replace it with
minSdkVersion Math.max(flutter.minSdkVersion, 21)
21 here can be replaced by whatever minimum version you would want.
In case flutter start supporting 23 or some other higher version as the minimum version and you decide to upgrade flutter for your project, it would still work.

**android/local.properties**
flutter.versionCode=1
flutter.minSdkVersion=21
flutter.targetSdkVersion=30
flutter.compileSdkVersion=31
**android/app/build.gradle**
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

I encountered this problem setting up Auth0, flutter_appauth and flutter_secure_storage within my flutter app. After changing the minSdkVersion version, I got this error
C:\Users\myusername\AndroidStudioProjects\wole\android\app\src\debug\AndroidManifest.xml Error:
Attribute data#scheme at AndroidManifest.xml requires a placeholder substitution but no value for <appAuthRedirectScheme> is provided.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : Attribute data#scheme at AndroidManifest.xml requires a placeholder substitution but no value for is provided.
The solution is adding manifestPlaceholders thus

Setting minSdkVersion, targetSdkVersion, and compileSdkVersion are a little bit different starting from Flutter 2.8. Now the gradle file in your_flutter_app/android/app/build.gradle path looks like this:
Just replace the current values with the version numbers you want, like this:
Now run your flutter project, and that's it.

change local.properties file mentioned below.. because currently playstore update minimum target api version atleast 30
sdk.dir=/Users/sweetnandha/Library/Android/sdk
flutter.sdk=/Users/sweetnandha/FlutterDev/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.compileSdkVersion=32
flutter.minSdkVersion=21
flutter.targetSdkVersion=32
or

It's found inside the defaultconfig on [project_name]/android/app/build.gradle. defaultconfig

you can find out that folder with which flutter ( on mac or linux ) or in windows you can look here https://stackoverflow.com/a/304447/8122500 .
then you can follow guide from #francis-nduba-numbi .
there is 2 type to change from
from flutter.gradle ( recommendation change here for not spesifc/for future )
or direct from build.gradle ( not recommended )

Try this at android/app/build.gradel minSdkVersion 30 that should fix it but make sure you are at kotlin_version = '1.6.10' with your kotlin version.

app/build.gradle add this version code

In the current version of flutter (2.10.4) you should change it by going into
Flutter sdk folder/packages/open flutter_tools open /gradle then open flutter.gradle and find static int minSdkVersion and change as per requirement
e.g:
C:\Workspace\flutter\packages\flutter_tools\gradle\flutter.gradle

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.map"
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

Upgrade your compiled sdk version to 29 - higher
hope this will help you.

this worked. With the new version, it can now be changed directly from the IDE.
https://www.youtube.com/watch?v=ztjCMzBX18w

first run
flutter clean
then change the minSdkVersion in the file Project_Name/android/app/build.gradle , defaultconfig :

Related

How to change minSdkVersion/targetSdkVersion in flutter 2.8? [duplicate]

I was trying to start a flutter project for an App using bluetooth to communicate. For that, I was using flutter blue.
Unfortunately, when trying to run (on an Android device) the first example I created I was met with the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:flutter_blue] /home/maldus/Projects/flutter/polmac/build/flutter_blue/intermediates/manifests/full/debug/AndroidManifest.xml as the library might be using APIs not available in 16
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="com.pauldemarco.flutterblue" to force usage (may lead to runtime failures)
If I were on Android Studio, I'd know how to bump up the Android minSdkVersion, but on a flutter project (using VSCode) I was a little lost.
Is it possible to increase the minSdkVersion with flutter, and how?
It is indeed possible to increase minSdkVersion, but it took me way too much time to find it out because google searches mostly yields as result discussions about the absolute minimum Sdk version flutter should be able to support, not how to increase it in your own project.
Like in an Android Studio project, you have to edit the build.gradle file. In a flutter project, it is found at the path ./android/app/build.gradle.
The parameter that needs to be changed is, of course, minSdkVersion 16, bumping it up to what you need (in this case 19).
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.projectname"
minSdkVersion 19 //*** This is the part that needs to be changed, previously was 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Seems obvious now, but took me long enough to figure it out on my own.
Flutter 2.8 or Later
build.gradle update
Before Updating to Flutter 2.8
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.example.app"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
After updating to Flutter 2.8:
android {
compileSdkVersion flutter.compileSdkVersion
defaultConfig {
applicationId "com.example.app"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
You should change from local.properties following instruction:
First go to the android->local.properties
And changes from here
Change like this from build.gradle
android {
compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()
defaultConfig {
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
If you didn't know, Google Playstore only allows minSdkVersion to be 20 or above. But flutter has still set default minSdkVersion to 16. Can you see that you'll be always obliged to manually change for each new project?
All your suggestions above are good, but they are not the best, because you will be forced to temper with the build.gradle for each new project you create.
The best way is to modify the value of the global minSdkVersion variable from its source, so all projects, new or old, will adopt it. Remember flutter.minSdkVersion means that the variable is in flutter directory (with the sdk).
The file in question is flutter.gradle.
the address is flutter-directory/packages/flutter_tools/gradle/flutter.gradle
class FlutterExtension {
/** Sets the compileSdkVersion used by default in Flutter app projects. */
static int compileSdkVersion = 31
/** Sets the minSdkVersion used by default in Flutter app projects. */
static int minSdkVersion = 16
/** Sets the targetSdkVersion used by default in Flutter app projects. */
static int targetSdkVersion = 31
change the value of the minSdkVersion from 16 to 20 or above, and do not disturb the code in build.gradle.
If you want, you can watch a video I made on Youtube, explaining it under: flutter configure minSdkVersion from 16 to 20 or above
For flutter v2.8
Inside local.properties add
sdk.dir='<path>'
flutter.sdk='<path>'
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=21
flutter.targetSdkVersion=30
flutter.compileSdkVersion=30
app-level build.gradle
defaultConfig {
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Now you can use localProperties.getProperty() to read the value from the properties file.
You can change the minSdkVersion in the file Project_Name/android/app/build.gradle , defaultconfig :
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.projectname"
minSdkVersion 16 // <--- There
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
With the new Flutter projects (2.8.0), with the 'Flutter style', you able to change minimum sdk version in local.properties (instead of editing app/build.gradle file).
# android/local.properties
flutter.minSdkVersion=19
Look in android/app/build.gradle file, you'll see the variable constraint like this:
# android/app/build.gradle
android {
defaultConfig {
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}
Here the detailed solution for changing MinSdk /Minsdk version error, follow the steps.
Add following lines on android\local.properties
sdk.dir=
flutter.sdk=C:\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=21
flutter.targetSdkVersion=31
flutter.compileSdkVersion=31
Delete existing lines and paste it on app level build.gradle: android\app\build.gradle
defaultConfig {
applicationId "app-id"
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Add the following lines to android/local.properties file:
flutter.versionCode=1
flutter.versionName=0.0.1
flutter.flutterMinSdkVersion=24
flutter.flutterTargetSdkVersion=31
Add the following lines at the top-level in the file may be after "def versionName =" in the file android/app/build.gradle:
def flutterMinSdkVersion = localProperties.getProperty('flutter.flutterMinSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = '16'
}
def flutterTargetSdkVersion = localProperties.getProperty('flutter.flutterTargetSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = '31'
}
finally edit the section of the build.gradle that match as follows:
defaultConfig {
applicationId "do.main.subdomain" // Use your App ID
minSdkVersion flutterMinSdkVersion.toInteger()
targetSdkVersion flutterTargetSdkVersion.toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Once all this is done you are good to go. Next time you want to update something you only have to change one file.
All answers are best. But the following way is best in changing SdkVersion after Flutter 2.8 :
Go to your root directory where flutter is installed. It should be like
C:\src\flutter\flutter
Then go to
packages>Flutter tools>gradle>
In Gradle, you will see many files, locate flutter.gradle . Right-click on it and edit it with text editor/notepad.
here you will find all SDK versions. Change them, save, and then you are ready to go
the complete path should be like this: (in my case)
C:\src\flutter\flutter\packages\flutter_tools\gradle
Follow these steps to change the minSdkVersion problem.
First=> YouProject_name/android/app/build.gradle
Second=> defaultconfig { //you can find it inside build.gradle }
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.umair.product_details_using_crud"
minSdkVersion 16 // here you can change minSdkVersison
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
I found the best way to fix this so it performs globally across all of your future apps as well is by changing the setting in the flutter.gradle file located in your default build section. If you're using VSCode
go to this location (or the location you've installed flutter)
C:\src\flutter\packages\flutter_tools\gradle\
drag the flutter.gradle file into VSCode
update the min, compile, and/or target versions
save
This is how I approached when I got this issue recently:
Inside <your-project>/android/app/build.gradle
Find android -> defaultConfig -> minSdkVersion and replace it with
minSdkVersion Math.max(flutter.minSdkVersion, 21)
21 here can be replaced by whatever minimum version you would want.
In case flutter start supporting 23 or some other higher version as the minimum version and you decide to upgrade flutter for your project, it would still work.
**android/local.properties**
flutter.versionCode=1
flutter.minSdkVersion=21
flutter.targetSdkVersion=30
flutter.compileSdkVersion=31
**android/app/build.gradle**
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
I encountered this problem setting up Auth0, flutter_appauth and flutter_secure_storage within my flutter app. After changing the minSdkVersion version, I got this error
C:\Users\myusername\AndroidStudioProjects\wole\android\app\src\debug\AndroidManifest.xml Error:
Attribute data#scheme at AndroidManifest.xml requires a placeholder substitution but no value for <appAuthRedirectScheme> is provided.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : Attribute data#scheme at AndroidManifest.xml requires a placeholder substitution but no value for is provided.
The solution is adding manifestPlaceholders thus
Setting minSdkVersion, targetSdkVersion, and compileSdkVersion are a little bit different starting from Flutter 2.8. Now the gradle file in your_flutter_app/android/app/build.gradle path looks like this:
Just replace the current values with the version numbers you want, like this:
Now run your flutter project, and that's it.
change local.properties file mentioned below.. because currently playstore update minimum target api version atleast 30
sdk.dir=/Users/sweetnandha/Library/Android/sdk
flutter.sdk=/Users/sweetnandha/FlutterDev/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.compileSdkVersion=32
flutter.minSdkVersion=21
flutter.targetSdkVersion=32
or
It's found inside the defaultconfig on [project_name]/android/app/build.gradle. defaultconfig
you can find out that folder with which flutter ( on mac or linux ) or in windows you can look here https://stackoverflow.com/a/304447/8122500 .
then you can follow guide from #francis-nduba-numbi .
there is 2 type to change from
from flutter.gradle ( recommendation change here for not spesifc/for future )
or direct from build.gradle ( not recommended )
Try this at android/app/build.gradel minSdkVersion 30 that should fix it but make sure you are at kotlin_version = '1.6.10' with your kotlin version.
app/build.gradle add this version code
In the current version of flutter (2.10.4) you should change it by going into
Flutter sdk folder/packages/open flutter_tools open /gradle then open flutter.gradle and find static int minSdkVersion and change as per requirement
e.g:
C:\Workspace\flutter\packages\flutter_tools\gradle\flutter.gradle
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.map"
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Upgrade your compiled sdk version to 29 - higher
hope this will help you.
this worked. With the new version, it can now be changed directly from the IDE.
https://www.youtube.com/watch?v=ztjCMzBX18w
first run
flutter clean
then change the minSdkVersion in the file Project_Name/android/app/build.gradle , defaultconfig :

My Flutter App is not running after adding cloud_firebase package

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.
It will work after changing the minSdkVersion to 21.
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
For the Projects Created After Flutter 2.8 Update
Add this to project_folder/android/local.properties
flutter.minSdkVersion=21
Now update your project_folder/android/app/build.gradle
defaultConfig { minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger() }
Run flutter clean && flutter pub get
Rerun app
Reference: Change Android Minsdkversion in Flutter  –  2 Easy Ways [2022]
Previous Answers are also correct. I just used another approach.
First add flutter.compileSdkVersion=21 in local.properties file.
Then add this code in app\build.gradle
def flutterMinSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = '21'
}
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 💪
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.
Try to add these lines to build.gradle file:
defaultConfig {
minSdkVersion 21
compileSdkVersion 33
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
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
}
}

Upgrading flutter android build tools

Flutter is building apk on android API level 29 by default I want to upgrade it to 30 how can I? I am new to flutter I don't know, I tried to google it but it wasn't helpful
Open a Flutter project in Android Studio and you have to edit the build.gradle file. In a flutter project, it is found at the path ./android/app/build.gradle
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.projectname"
minSdkVersion 19
targetSdkVersion 28 // Set this to 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Inspiration from this answer and modified accordingly

Import BuildConfig in Android Studio using Gradle

I am new to Android Studio and I am trying to get versionCode in build.gradle.
I have read this post and this post, and I tried their solution:
import com.example.BuildConfig;
...
...
...
// Get current version code
int currentVersionCode = BuildConfig.VERSION_CODE;
But IDE keeps saying Cannot resolve symbol 'BuildConfig'. Actually I haven't found any string in the whole project folder named "BuildConfig" (searched in Windows Explorer). Is there something wrong with my project configuration/creation?
defaultConfig in build.gradle (module: app) is like
defaultConfig {
applicationId "com.foo.bar"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Your BuildConfig should always be:
import <applicationId>.BuildConfig (replacing <applicationId> with its value)
If you're still getting the error after trying that, then select invalidate caches / restart from the menu. This happened to me, went googling this error, then had a "duh" moment as I remembered that trick. Invalidating your caches will often fix compilation errors that seem like they shouldn't be happening.
You get to it statically like so....
com.foo.project.BuildConfig.VERSION_CODE; //this value will be an int
In your 'Module: app' Gradle file all of this info can be found in the 'defaultConfig' section.
defaultConfig {
applicationId 'com.foo.project'
minSdkVersion 21
targetSdkVersion 29
versionCode 18
versionName '2.6'
signingConfig signingConfigs.config
}

Getting issue while importing (Mateial Design calendar) library module in android studio

I am getting this error ,how to fix it.
Error:(12, 0) Cannot get property 'versionCodeInt' on extra properties extension as it does not exist
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode project.ext.versionCodeInt -> getting error this line
versionName version
}
Error:(12, 0) Cannot get property 'versionCodeInt' on extra properties
extension as it does not exist
This error means that variable versionCodeInt which you are trying to use in build.gradle of Module level is not properly set up in build.gradle file of Project's root level.
So, please check if root build.gradle contains such code:
project.ext {
versionCodeInt = 2 // actually here should be your current version code
}
try this, it's working for me
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}

Categories

Resources