【问题标题】:Failed to precompile flutter_launcher_icons:main:无法预编译 flutter_launcher_icons:main:
【发布时间】:2021-04-09 08:04:14
【问题描述】:

所以我尝试使用 flutter_launcher_icons 自动更改我的简单兴趣计算器应用的启动器图标。

这是我在 pubspec.yaml 中的代码


dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.0
  flutter_launcher_icons: ^0.8.1

dev_dependencies:

  flutter_test:
    sdk: flutter

  flutter_launcher_icons: "^0.8.0"

flutter_icons:
  android: "launcher_icon"
  ios: true
  image_path: "assets/icon.png"

flutter:
  uses-material-design: true

我在运行 flutter pub get & 后得到的错误 flutter pub 运行 flutter_launcher_icons:main

Failed to precompile flutter_launcher_icons:main:
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_launcher_icons-0.8.1/lib/utils.dart:1:8: Error: Error when reading '/C:/src/flutter/flutter/.pub-cache/hosted/
pub.dartlang.org/image-2.1.19/lib/image.dart': The system cannot find the path specified.

import 'package:image/image.dart';
       ^
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_launcher_icons-0.8.1/lib/android.dart:4:8: Error: Error when reading '/C:/src/flutter/flutter/.pub-cache/hoste
d/pub.dartlang.org/image-2.1.19/lib/image.dart': The system cannot find the path specified.

import 'package:image/image.dart';
       ^
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_launcher_icons-0.8.1/lib/utils.dart:3:1: Error: Type 'Image' not found.
Image createResizedImage(int iconSize, Image image) {
^^^^^
                                                 ^^^^^
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_launcher_icons-0.8.1/lib/ios.dart:93:1: Error: Type 'Image' not found.
Image createResizedImage(IosIconTemplate template, Image image) {
^^^^^
pub finished with exit code 1

【问题讨论】:

    标签: flutter flutter-dependencies


    【解决方案1】:

    你可以这样改;

    flutter_icons:
      android: true
      ios: true
      image_path: "assets/icon.png"
    

    并且不需要使用那个 import 'package:image/image.dart';如果您从资产中获取图像,则无需像那样导入它。您应该创建一个名为 assets 的文件并将图像放入其中

    然后将其粘贴到终端中。

    flutter pub run flutter_launcher_icons:main
    

    【讨论】:

    • 我已将其更改为 flutter_icons: android: true ios: true image_path: "assets/icon.png" ,我已经创建了一个名为 assets 的文件夹,并且 icon.png 已经在其中。再次尝试颤振pub run flutter_launcher_icons:main,但同样的错误。
    • 你删除了 import 'package:image/image.dart';
    【解决方案2】:

    您没有在dev_dependencies 下正确导入flutter_launcher_icons 包。您不应该使用引号(“)。您可以使用以下内容编辑该部分:

    dev_dependencies:
    
      flutter_test:
        sdk: flutter
    
      flutter_launcher_icons: ^0.8.0
    

    【讨论】:

      【解决方案3】:

      在我的情况下,图像包没有被正确下载,所以我去了 ~\flutter.pub-cache\hosted\pub.dartlang.org\image-3.0.8 并从 git 克隆了代表:https://github.com/brendan-duncan/image

      之后该命令起作用了。

      【讨论】:

      猜你喜欢
      • 2021-08-14
      • 2021-05-07
      • 1970-01-01
      • 2021-10-24
      • 2012-03-26
      • 1970-01-01
      • 2013-12-13
      相关资源
      最近更新 更多