简体   繁体   English

Flutter项目中“flutter.minSdkVersion”的值在哪里初始化?

[英]Where is the value of "flutter.minSdkVersion" in Flutter project initialized?

I have created a new Flutter project, and this is how the minSdkVersion looks like in the app/build.gradle file:我创建了一个新的 Flutter 项目,这就是 minSdkVersion 在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 flutter.minSdkVersion
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

Where is the value of flutter.minSdkVersion set? flutter.minSdkVersion的值在哪里设置?

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:此外,这是android/local.properties文件的内容:

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.可以看到,这里并没有设置flutter.minSdkVersion的值,但是工程可以编译构建成功。

Where are the flutter.minSdkVersion and flutter.targetSdkVersion variables initialized? flutter.minSdkVersionflutter.targetSdkVersion变量在哪里初始化?

PS related issue: https://github.com/flutter/flutter/issues/95533 PS相关问题: https://github.com/flutter/flutter/issues/95533

Go to this file in your flutter extracted folder: Go 到您的 flutter 提取文件夹中的此文件:

flutter/packages/flutter_tools/gradle/flutter.gradle颤振/包/flutter_tools/gradle/flutter.gradle

There you can find all static variables.在那里您可以找到所有 static 变量。

You should change from local.properties following instruction:您应该按照以下说明从 local.properties 进行更改:

  1. First go to the android-> local.properties首先 go 到 android-> local.properties

  2. And changes from here local.properties并从这里更改local.properties

add this line添加这一行

flutter.minSdkVersion=19
flutter.targetSdkVersion=28
flutter.compileSdkVersion=28

NB: you don't find the local.properties you create yourself注意:您找不到自己创建的local.properties

Put in your android/local.propertie file the variable:将变量放入您的android/local.propertie文件中:

Example:例子:

flutter.minSdkVersion=21

And change in android/app/build.gradle并更改android/app/build.gradle

localProperties.getProperties('flutter.minSdkVersion') // flutter.minSdkVersion 

Just replace flutter.minSdkVersion with your required value such as 19 like old style只需将flutter.minSdkVersion替换为您需要的值,例如旧样式的19

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按照路径/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

}`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM