Flutter build apk - 请更新您的 settings.gradle 文件

Posted

技术标签:

【中文标题】Flutter build apk - 请更新您的 settings.gradle 文件【英文标题】:Flutter build apk - please update your settings.gradle file 【发布时间】:2020-07-16 07:11:07 【问题描述】:

Flutter run 在 mac os 上运行良好 但是当我尝试构建我的应用程序的发布 apk 版本时,它会引发几个 gradle 错误:

Plugin Project preferences not found please update settings.gradle
Plugin Project :drawer behavior not found please update settings.gardle
Plugin Project :Google-maps not found please update settings.gradle

【问题讨论】:

好的,你为什么不更新settings.gradle? settings.gradle 文件中没有要更新的内容 include ':app' def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() def plugins = new Properties() def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-dashboard.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 这是settings.gradle里面的代码 @MohammadMoeinGolchin 你知道吗? 【参考方案1】:

我发现问题与settings.gradle有关 使用旧版本的文件一切正常。 在我的具体情况下,moor_ffi 没有构建,共享库 libsqlite 也没有包含在 apk 中。

这是工作文件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

这是最近的不工作 settings.gradle:

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"

参考链接 GitHub Flutter Issus

【讨论】:

我在 moor_ffi 上遇到了同样的问题,但你的解决方案对我不起作用:(【参考方案2】:

使用如下所示的旧版本 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

【讨论】:

以上是关于Flutter build apk - 请更新您的 settings.gradle 文件的主要内容,如果未能解决你的问题,请参考以下文章

如何解决“flutter build apk”上的此错误

flutter电子木鱼flutter 打包 android apk,记录配置签名的过程/调试的过程及flutter build apk放到手机上用。

flutter电子木鱼flutter 打包 android apk,记录配置签名的过程/调试的过程及flutter build apk放到手机上用。

Flutter:build/app/outputs下的apk/release目录和flutter-apk目录有啥区别?

Flutter 卡在安装 build\app\outputs\apk\app.apk

Flutter 运行卡在安装 build\app\outputs\apk\app.apk