2
2

More than 1 year has passed since last update.

[Flutter]FlutterでAndroidのcompileSdkVersion,targetSdkVersion,minSdkVersionを変更する方法

Posted at

はじめに

以前までは、バージョン更新はapp直下のbuild.gradleの設定で行っていました。
変数を使う場合も同ファイルで行っていましたが、現在はflutter.minSdkVersionのようにflutterの設定ファイルから取得しているようです。ガン無視してダイレクトに記載しても動作しますが、作法がよろしくないので、flutterの設定をいじって直すにはどうしたらいいのかを調べました。

    defaultConfig {
        applicationId "com.example.hogehoge"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

解決

flutterのSDKをインストール(デフォルトだとユーザ名直下)した場所から下記のパスの位置にあります

~/flutter/packages/flutter_tools/gradle

この中のflutter.gradleファイルです。

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 = 28 // ←これ

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

上記のminSdkVersion、targetSdkVersion、compileSdkVersionの部分を更新することで解決します。

なんでこんな面倒になったのでしょうか。個人的にはこれらのバージョンはアプリ仕様によって変えるべきだと思っているので、共通部でこの設定はイマイチですね。まあapp直下のbuild.gradleを直接変更でも作法はよろしくないが、場合によりその方がいいかと思います。

最後に

FlutterはAndroidやiOSで個別にバージョンやアプリ名、ローカライズ、アイコン設定などなどやることがあるため、Android,iOS開発もある程度知見がないとまだまだ敷居がたかいものです。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2