flutter A problem occurred configuring project ‘:shared_preferences_linux‘.

错误如下:

FAILURE: Build failed with an exception.

 

* Where:

Script '/Users/xuhang/MyFiles/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 363

 

* What went wrong:

A problem occurred configuring project ':shared_preferences_linux'.

> Could not find method compile() for arguments [project ':path_provider_linux'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

 

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

 

* Get more help at https://help.gradle.org

 

BUILD FAILED in 1s

Finished with error: Gradle task assembleDebug failed with exit code 1

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

问题原因:

flutter shared_preferences插件里面含【shared_preferences_linux、shared_preferences_macos、shared_preferences_web】

这些插件在打包apk或ios应用时候不需要用到,build.gradle会报错

 

解决办法:

第一步:删除shared_preferences插件(如下图),重新flutter packages get(重新安装shared_preferences插件)

第二步:找到shared_preferences插件下的pubspec.yaml 移除【shared_preferences_linux、shared_preferences_macos、shared_preferences_web】

 

pubspec.yaml修改后如下(shared_preferences_linux、shared_preferences_macos、shared_preferences_web)我都注释

name: shared_preferences
description: Flutter plugin for reading and writing simple key-value pairs.
  Wraps NSUserDefaults on iOS and SharedPreferences on Android.
homepage: https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences
# 0.5.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 0.5.8

flutter:
  plugin:
    platforms:
      android:
        package: io.flutter.plugins.sharedpreferences
        pluginClass: SharedPreferencesPlugin
      ios:
        pluginClass: FLTSharedPreferencesPlugin
      #linux:
      #  default_package: shared_preferences_linux
      #macos:
      #  default_package: shared_preferences_macos
      #web:
      #  default_package: shared_preferences_web

dependencies:
  meta: ^1.0.4
  flutter:
    sdk: flutter
  shared_preferences_platform_interface: ^1.0.0
  # The design on https://flutter.dev/go/federated-plugins was to leave
  # this constraint as "any". We cannot do it right now as it fails pub publish
  # validation, so we set a ^ constraint.
  # TODO(franciscojma): Revisit this (either update this part in the  design or the pub tool).
  # https://github.com/flutter/flutter/issues/46264
  # shared_preferences_linux: ^0.0.2
  # shared_preferences_macos: ^0.0.1
  # shared_preferences_web: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_driver:
    sdk: flutter
  test: any
  e2e: ^0.2.0
  pedantic: ^1.8.0

environment:
  sdk: ">=2.1.0 <3.0.0"
  flutter: ">=1.12.13+hotfix.5 <2.0.0"

 

第三步:flutter run 验证,若是不行请执行最通用的flutter doctor 或许能帮助你!

总结:flutter build失败通常都是依赖的包,引用了不需要的内容,大部分这些问题要找到这些都难解决!少数是build的目标安卓版本问题(受插件,有些插件用到的api可能与最新的android api有细微兼容性)

 

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2022 CSDN 皮肤主题:数字20 设计师:CSDN官方博客 返回首页

打赏作者

BlueSky_x

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值