Anushka Pubudu
Anushka Pubudu

Reputation: 427

Change Android minSDk Version Flutter New SDK

I need to change SDK version on Android but now on build.gradle (in root/android/app/build.gradle) looks like

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

I know I can replace with flutter.minSdkVersion to version code manually (I tried, It works). But I need to know the best way...

Update: I'm Using Flutter 2.8.1 • channel stable & Dart 2.15.1

Upvotes: 2

Views: 1440

Answers (4)

Sweta Jain
Sweta Jain

Reputation: 4324

None of the above methods is working or is reliable.

Please follow the steps below to fix this issue:

Step 1. Locate the Flutter SDK on your device. Step 2. Locate the packages folder inside.

enter image description here

Step 3. Go inside packages -> flutter-tools -> gradle -> flutter

enter image description here

Step 4. Double-click the flutter folder and open it in notepad to edit.

Step 5. Edit the required min SDK variable inside and save the file.

enter image description here

Step 6. Rerun the app and you will find no error now.

Thanks :)

Upvotes: 0

keyur
keyur

Reputation: 181

You can directly change the min SDK version in build.gradle file

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.bla.bla"
    minSdkVersion 'You can set version // for ex.16'  
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

Upvotes: 0

Tasnuva Tavasum oshin
Tasnuva Tavasum oshin

Reputation: 4750

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
  }
}

Upvotes: 0

Michele Volpato
Michele Volpato

Reputation: 760

You can use Math.max:

defaultConfig {
        applicationId "com.bla.bla"
        minSdkVersion Math.max(flutter.minSdkVersion, 19)  // here is the change
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

But personally I would just use the specific version number.

Upvotes: 2

Related Questions