How to change Android minSdkVersion in flutter project

前端 未结 4 1516
梦毁少年i
梦毁少年i 2020-12-04 20:50

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 Andro

相关标签:
4条回答
  • 2020-12-04 21:07

    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
        }
    
    0 讨论(0)
  • 2020-12-04 21:11

    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"
    }
    
    0 讨论(0)
  • 2020-12-04 21:17

    If your app requires a specific minimum version of the Android platform, you can specify that version requirement as API level settings in the app's build.gradle file. During the build process, these settings are merged into your app's manifest file. Specifying API level requirements ensures that your app can only be installed on devices that are running a compatible version of the Android platform.

    You have to do set minSdkVersion in build.gradle file, located in <app dir>/android/app and set a value in the defaultConfig block:

    There are two API level settings available:

    • minSdkVersion — The minimum version of the Android platform on which the app will run, specified by the platform's API level identifier.
    • targetSdkVersion — Specifies the API level on which the app is designed to run. In some cases, this allows the app to use manifest elements or behaviors defined in the target API level, rather than being restricted to using only those defined for the minimum API level.

    To specify default API level requirements in a build.gradle file, add one or more of the settings above to the defaultConfig {} block, nested inside the android {} block. You can also override these default values for different versions of your app by adding the settings to build types or product flavors. The following build.gradle file specifies default minSdkVersion and targetSdkVersion settings in the defaultConfig {} block and overrides minSdkVersion for one product flavor.

    android {
       compileSdkVersion 29
    
      ...
      defaultConfig {
        applicationId "com.app.yourapp”
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
      }
      productFlavors {
        main {
          ...
        }
        afterLollipop {
          ...
          minSdkVersion 21
        }
      }
    }
    

    For more information, see the uses-sdk-element manifest element documentation and the API Levels document.

    0 讨论(0)
  • 2020-12-04 21:27

    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.

    0 讨论(0)
提交回复
热议问题