Integrate a Flutter module into your Android project(Arctic Fox)

とりあえず、起動はできたがArctic Foxだとスムーズにはいかない

新しくプロジェクトを作って、flutter_moduleを追加してgradle sync

下記エラーが発生

Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin class 'FlutterPlugin'.

stackoverflow

android - PluginApplicationException: Failed to apply plugin class 'FlutterPlugin' - Stack Overflow

Arctic Foxで新規作成した時のgradleのバージョンとflutterが適合するバージョンが違う模様

Could not find method dependencyResolutionManagement()

ダウングレードすると今度はメソッドが見つからない

Settings file '/Users/takayuki/AndroidStudioProjects/FlutterIntoAndroid/settings.gradle' line: 3

A problem occurred evaluating settings 'FlutterIntoAndroid'.
> Could not find method dependencyResolutionManagement() for arguments [settings_attxq7gxzoa167j848a5dg0iu$_run_closure1@7de31858] on settings 'FlutterIntoAndroid' of type org.gradle.initialization.DefaultSettings.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating settings 'FlutterIntoAndroid'.

中略

Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method dependencyResolutionManagement() for arguments [settings_attxq7gxzoa167j848a5dg0iu$_run_closure1@7de31858] on settings 'FlutterIntoAndroid' of type org.gradle.initialization.DefaultSettings.

arctic-foxからDependencyResolutionManagementがsettings.gradleに追加されるようになった

https://androidstudio.googleblog.com/2021/02/android-studio-arctic-fox-canary-7.html

DependencyResolutionManagementはいつから?

DependencyResolutionManagement (Gradle API 7.2)

6.8から

ちなみにgradle release一覧 Gradle | Releases

flutter_toolsのソースを眺める

https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/android/gradle_utils.dart#L183

この辺りをウォッチングしておけばいい?

flutter createのテンプレートは下記

https://github.com/flutter/flutter/blob/master/packages/flutter_tools/templates/app_shared/android-kotlin.tmpl/build.gradle#L9

dependencyResolutionManagementのブロックを削除

repositoriesの設定をしているだけのように見えるので削除

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}

そうすると下記のエラーが発生

FAILURE: Build completed with 9 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.20.
     Searched in the following locations:
       - https://storage.googleapis.com/download.flutter.io/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.5.20/kotlin-stdlib-jdk8-1.5.20.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project :app

基本に立ち戻ってsamplesを見る

https://github.com/flutter/samples/tree/master/add_to_app

プロジェクトのbuild.gradleにallprojects.repositoriesがないことに気づいて追加。そうするとビルドが成功してアプリが立ち上がるようになった。

でも、まだflutterのコードと連携できるようにはなってない。

検証中のリポジトリ

https://github.com/na8esin/flutter_into_android