Within ../android/app/build.gradle, there is a section that looks like this:
android {
defaultConfig {
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}
Now, flutter.minSdkVersion seems to be a variable located in which file within my project?
It is the default values flutter takes.
You should updates these as per needed. For latest flutter android build, it should be
android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}
You have to go to \android\local.properties
Then add
flutter.minSdkVersion = 26 // the version is up to your needs.
flutter.targetSdkVersion = 32
After that return to defaultConfig of build.gradle and call it like this :
defaultConfig {
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Don't forget to launch a flutter clean flutter pub get and then flutter run
Related
I am getting this error after updating minSdkVersion according to this question's answer.
Here is the error.
(For some reason I can't post the raw error output.)
Here is my build.gradle:
defaultConfig {
applicationId "com.example.test_app"
// modified this as per the solution
minSdkVersion localProperties.getProperty(‘flutter.minSdkVersion’).toInteger()
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Here is my local.propertis
sdk.dir=C:\\Users\\userone\\AppData\\Local\\Android\\sdk
flutter.sdk=C:\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
// added this as per the solution
flutter.minSdkVersion=21
where should i find minSdkVersion from 16 to 21
android/app/build.gradle
it will look like this
defaultConfig {*
applicationId "***"
minSdkVersion 22
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName*
}
In the old version, we could change it via android/app/build.gradle. Now it gives an error when we change it.
defaultConfig {
applicationId "com.example.manuel"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
There are those who fix this problem via local.properties, but this method does not work either.
sdk.dir=C:/Users/user/AppData/Local/Android/Sdk
flutter.sdk=C:\\src\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
you need to edit the build.gradle file in the new version as well. As follows;
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.manuel"
minSdkVersion 16 // <--- There minSdkVersion Content
targetSdkVersion 27 <--- There targetSdkVersion (is actually Max Sdk Version) Content
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
then rebuild the project and build it again.
I hope that will be useful.
I have created a new Flutter project, and this is how the minSdkVersion looks like in the app/build.gradle file:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.projectname"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Where is the value of flutter.minSdkVersion set?
Note that previously, that config value looked like the following:
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"
}
Also, this is the content of the android/local.properties file:
sdk.dir=/Users/usernaem/Library/Android/sdk
flutter.sdk=/Users/username/flutter
flutter.buildMode=release
flutter.versionName=1.0.0
flutter.versionCode=1
As you can see, the value of flutter.minSdkVersion is not set there, but the project can be compiled and built successfully.
Where are the flutter.minSdkVersion and flutter.targetSdkVersion variables initialized?
P.S. related issue: https://github.com/flutter/flutter/issues/95533
Go to this file in your flutter extracted folder:
flutter/packages/flutter_tools/gradle/flutter.gradle
There you can find all static variables.
Put in your android/local.propertie file the variable:
Example:
flutter.minSdkVersion=21
And change in android/app/build.gradle
localProperties.getProperties('flutter.minSdkVersion') // flutter.minSdkVersion
Just replace flutter.minSdkVersion with your required value such as 19 like old style
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.projectname"
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Follow 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.sample.com"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 23
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
I wonder if it is possible to set String placeholder for versionCode in android.defaultConfig.
We run a build machine that should replace all <REPLACE> places with original values but versionCode excepts integer only.
Something like:
android {
compileSdkVersion 26
defaultConfig {
targetSdkVersion 26
minSdkVersion 14
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode "<REPLACE_VERSION_CODE>"
versionName "<REPLACE_VERSION_NMAE>"
Any ideas how to make it work?
So far I left versionCode -99999 but I look for more gentle solution
How about creating a variable in the gradle file and set it to some default value (e.g -99999) that can be replaced by your build machine.
For example
android {
compileSdkVersion 26
def version_code = -99999
defaultConfig {
targetSdkVersion 26
minSdkVersion 14
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode version_code
versionName "<REPLACE_VERSION_NMAE>"
}
}
This way you have a readable text (not int) on the versionCode line.