【Flutter】You are applying Flutter's app_plugin_loader...

ネコニウム研究所

PCを利用したモノづくりに関連する情報や超個人的なナレッジを掲載するブログ

【Flutter】You are applying Flutter's app_plugin_loader...

2024-4-18 |
200px200px200px200px

Flutterを更新後のAndroidへのビルドで表示されるYou are applying Flutter's app_plugin_loader...をなんとかしたい!

概要

今回の記事では、Flutterを更新後のAndroidのビルドで表示されるYou are applying Flutter's app_plugin_loader...をなんとかする手順を掲載する。

表示される警告文の全文は下記の様な感じ。

You are applying Flutter's app_plugin_loader Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block

私の環境では3.13.5で作ったプロジェクトを3.19.6で開いてAndroidへのビルドを行った時にこの警告文が表示された。
ビルド自体はできてるんだけども、こんなん赤字で表示されたら気になる!気になって夜しか寝れない!

仕様書

環境

  • Android Studio Giraffe | 2023.2.1 Patch 2
  • Flutter 3.13.5 -> 3.19.6

手順書

後述の参考文献・引用のサイトを参考にさせていただきました。ありがとうございました。

gradle関連の書き方が変わったみたい。それぞれ設定ファイルを修正する。

android/settings.gradle

111行目(全文)の下記を削除するかコメントアウトする。

//include ':app'

//def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
//def properties = new Properties()

//assert localPropertiesFile.exists()
//localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }

//def flutterSdkPath = properties.getProperty("flutter.sdk")
//assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
//apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

下記を追加。

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.8.22" apply false
    id "com.google.gms.google-services" version "4.4.0" apply false
    id "com.google.firebase.crashlytics" version "2.9.9" apply false
}

include ":app"

android/build.gradle

112行目の下記を削除するかコメントアウトする。

//buildscript {
//    ext.kotlin_version = '1.7.10'
//    repositories {
//        google()
//        mavenCentral()
//    }
//
//    dependencies {
//        classpath 'com.android.tools.build:gradle:7.4.2'
//        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
//    }
//}

2行目のext.kotlin_version = '1.7.10'のバージョンの値を覚えておく。1.7.10の部分。

android/app/build.gradle

912行目の下記を削除するかコメントアウトする。

//def flutterRoot = localProperties.getProperty('flutter.sdk')
//if (flutterRoot == null) {
//    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
//}

2426行目の下記を削除するかコメントアウトする。

//apply plugin: 'com.android.application'
//apply plugin: 'kotlin-android'
//apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

69行目のdependenciesの前の行に下記を追加。値はandroid/build.gradleext.kotlin_versionの値を入力する。この記事の場合は1.7.10

def kotlin_version = "1.7.10"

ファイルの先頭に下記を追加。

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
//    id "com.google.gms.google-services"
//    id "com.google.firebase.crashlytics"
}

コメントアウトしてるcom.google.gms.google-servicescom.google.firebase.crashlyticsはプロジェクトの設定によってコメントアウトしたりしなかったり。私のプロジェクトではコメントアウトを解除すると別のエラーが発生してビルド自体ができなくなってしまった。そのエラーのメッセージは下記のような感じ。

Execution failed for task ':app:processDebugGoogleServices'.
File google-services.json is missing. The Google Services Plugin cannot function without it.

おそらくFireBaseを使ってると必要になるパッケージだと思われ。

まとめ(感想文)

こういうのってFlutterの更新の時に勝手にやってくれるかコマンド実行したらなんとかなるようにして欲しいと思う今日この頃。めんどいじゃん。

参考文献・引用

下記のサイトを参考にさせていただきました。ありがとうございました。