【问题标题】:Change Android minSDk Version Flutter New SDK更改 Android minSDk 版本 Flutter 新 SDK
【发布时间】:2022-01-22 15:12:44
【问题描述】:

我需要在 Android 上更改 SDK 版本,但现在 build.gradle(在 root/android/app/build.gradle 中)看起来像

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
    }

我知道我可以手动将 flutter.minSdkVersion 替换为 版本代码(我试过了,它有效)。但我需要知道最好的方法...

更新: 我正在使用 Flutter 2.8.1 • channel stable 和 Dart 2.15.1

【问题讨论】:

  • 参考here
  • @gretal 我知道我可以用 flutter.minSdkVersion 替换手动版本代码(我试过了,它有效)。但我需要知道最好的方法......
  • 我认为只能手动完成。
  • 您是在问是否可以重新定义 flutter.minSdkVersion 本身?我不认为是。

标签: flutter


【解决方案1】:

你可以使用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
    }

但我个人只会使用特定的版本号。

【讨论】:

    【解决方案2】:

    使用新的 Flutter 项目 (2.8.0),使用“Flutter 样式”,您可以在 local.properties 中更改最低 sdk 版本(而不是编辑 app/build.gradle 文件)。

    # android/local.properties
    
    flutter.minSdkVersion=19
    Look in android/app/build.gradle file, you'll see the variable 
    

    这样的约束:

    # android/app/build.gradle
    
    android {
    
      defaultConfig {
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
      }
    }
    

    【讨论】:

      【解决方案3】:

      您可以直接在 build.gradle 文件中更改最低 SDK 版本

      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
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-19
        • 2017-07-27
        • 2023-03-05
        • 2020-10-16
        • 1970-01-01
        • 2023-02-24
        相关资源
        最近更新 更多