Flutter: Android构建minSdkVersion,targetSdkVersion配置

我们在使用构建Android客户端客户端的时候,时常要在android/app/build.gradle文件中进行配置。其中minSdkVersion targetSdkVersion也是在此配置。

文件中相关的内容如下:

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.flutter_start"
    // You can update the following values to match your application needs.
    // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
    minSdkVersion flutter.minSdkVersion
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

但是搜遍了项目也没有看到minSdkVersion targetSdkVersion这两个字段的具体内容是在那里声明的。

结果

文件所有flutter配置都声明在:

flutter_sdk/packages/flutter_tools/gradle/flutter.gradle
其中flutter_sdk为您的flutter sdk所在路径

flutter.gradle文件内容为:

/ Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file exists solely for the compatibility with projects that have
// not migrated to the declarative apply of the Flutter Gradle Plugin.

def pathToThisDirectory = buildscript.sourceFile.parentFile
apply from: "$pathToThisDirectory/src/main/groovy/flutter.groovy"

可以看到文件的具体内容指向了"$pathToThisDirectory/src/main/groovy/flutter.groovy",所以找到flutter_sdk/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy文件即可看到真正的声明内容。

部分内容如下:

class FlutterExtension {
    /** Sets the compileSdkVersion used by default in Flutter app projects. */
    static int compileSdkVersion = 33

    /** Sets the minSdkVersion used by default in Flutter app projects. */
    static int minSdkVersion = 19

    /** Sets the targetSdkVersion used by default in Flutter app projects. */
    static int targetSdkVersion = 33

    /**
     * Sets the ndkVersion used by default in Flutter app projects.
     * Chosen as default version of the AGP version below as found in
     * https://developer.android.com/studio/projects/install-ndk#default-ndk-per-agp
     */
    static String ndkVersion = "23.1.7779620"

    /**
     * Specifies the relative directory to the Flutter project directory.
     * In an app project, this is ../.. since the app's build.gradle is under android/app.
     */
    String source

    /** Allows to override the target file. Otherwise, the target is lib/main.dart. */
    String target
}
ON THIS PAGE
浙ICP备2023004975号-2
浙公网安备33011002017713号