MOOR : moor_ffiが読み込まれない問題

プログラミング

flutterの勉強中に何度か時間を食ってしまったエラーの個人的なメモです。

Plugin project :moor_ffi not found. Please update settings.gradle.

このようなエラーが出てデータベースがうまく動かないことがあったのですが、ググったら解決しました。

Flutter build apk - please update your settings.gradle file
Flutter run works perfectly fine on mac os But when I try to build a release apk version of my app it throws a couple of gradle errors: Plugin Project preferen...

ちなみに各種バージョンは以下の通り。

[√] Flutter (Channel stable, v1.17.3, on Microsoft Windows [Version 10.0.18363.900], locale ja-JP)
    • Flutter version 1.17.3 at E:\Developer\flutter
    • Framework revision b041144f83 (13 days ago), 2020-06-04 09:26:11 -0700
    • Engine revision ee76268252
    • Dart version 2.8.4


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at C:\Users\kyama\AppData\Local\Android\sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: E:\Developer\android studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 4.0)
    • Android Studio at E:\Developer\android studio
    • Flutter plugin version 46.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.44.2)
    • VS Code at C:\Users\kyama\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.11.0

[√] VS Code, 64-bit edition (version 1.46.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.11.0

解決策としては、エラーにも出ているのですが android ディレクトリ直下の settings.gradle の内容を以下のように書き換えるとエラーは消えます。

変更前

include ':app'

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
    pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}

plugins.each { name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    include ":$name"
    project(":$name").projectDir = pluginDirectory
}

変更後

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"

これだけで解決するはず。この記事が誰かのお役に立てれば幸いです。

コメント