You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter Flame游戏在iOS与macOS无法启动,报Images类型未找到错误

简单Flame游戏无法运行:Images类型未找到错误

创建了一个无内容的简单Flame游戏,但无法正常运行,核心错误为Images类型未找到,iOS和macOS端均出现类似报错。

iOS端报错

Error (Xcode): ../../../../../.pub-cache/hosted/pub.dev/flame-1.6.0/lib/src/game/game.dart:25:3: Error: Type 'Images' not found. game.dart:25 Could not build the application for the simulator. Error launching application on iPhone 14.

macOS端报错

: Error: 'Images' isn't a type.
parallax.dart:354
    Images? images,
    ^^^^^^
: Error: 'Images' isn't a type.
parallax.dart:369
    Images? images,
    ^^^^^^
: Error: 'Images' isn't a type.
parallax.dart:393
    Images? images,
    ^^^^^^
: Error: 'Images' isn't a type.
parallax.dart:485
    Images? images,
    ^^^^^^
Target kernel_snapshot failed: Exception

Command PhaseScriptExecution failed with a nonzero exit code

warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Flutter Assemble' from project 'Runner')
** BUILD FAILED **

注:"Images is not available"这类错误出现频率比上述代码块中展示的更高。

pubspec.yaml配置

name: dash_jump
description: A new Flutter project.
publish_to: 'none'

version: 1.0.0+1

environment:
  sdk: '>=2.19.4 <3.0.0'

dependencies:
  cupertino_icons: ^1.0.2
  flame: ^1.6.0
  flutter:
    sdk: flutter

dev_dependencies:
  flutter_lints: ^2.0.0
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

测试代码

import 'package:flame/game.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(GameWidget(game: MyGame()));
}

class MyGame extends FlameGame {}

flutter doctor -v结果

flutter doctor -v
[✓] Flutter (Channel stable, 3.7.7, on macOS 13.2.1 22D68 darwin-arm64, locale
    de-DE)
    • Flutter version 3.7.7 on channel stable at
      /Users/Max/Documents/Development/SDKs/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2ad6cd72c0 (5 days ago), 2023-03-08 09:41:59 -0800
    • Engine revision 1837b5be5f
    • Dart version 2.19.4
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Volumes/Max/SDK/Android
    • Platform android-33, build-tools 33.0.1
    • Java binary at:
      /opt/homebrew/Cellar/openjdk/19.0.2/libexec/openjdk.jdk/Contents/Home/bin/
      java
    • Java version OpenJDK Runtime Environment Homebrew (build 19.0.2)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✗] Chrome - develop for the web (Cannot find Chrome executable at
    /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2022.1)
    • Android Studio at /Volumes/Max/Programme/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.76.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (1 available)
    • macOS (desktop) • macos • darwin-arm64 • macOS 13.2.1 22D68 darwin-arm64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

已尝试的解决方案

  • 运行flutter clean清理缓存
  • 删除并重建项目
  • 重启电脑

问题仍未解决。

解决方法

核心原因是Flame 1.6.0与当前Flutter 3.7.7版本存在兼容性问题,Images类的定义或导入路径在该版本组合下出现异常。

  1. 修改pubspec.yaml中的Flame依赖版本为兼容Flutter 3.7.7的稳定版,例如:
    dependencies:
      flame: ^1.8.0
    
  2. 执行flutter pub get重新获取依赖
  3. 再次执行flutter clean,然后重新运行项目

内容的提问来源于stack exchange,提问作者MultiMedia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 00:37:09