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

Flutter引用父目录资源构建报错,求外部文件夹无冲突引用方案

Flutter引用外部图片文件夹构建失败

尝试的资源配置

我尝试在Flutter的资源配置中引用外部图片文件夹:

assets:
    - ../backend/uploaded_images/

构建错误信息

首次运行应用无报错,但再次运行时构建失败,抛出以下错误:

Target debug_android_application failed: FileSystemException: Cannot copy file to 'C:\Users\nuras\CS_Projects\miras\farmer_market\flutter\build\app\intermediates\flutter\debug\flutter_assets\../backend/uploaded_images/13afcc89-36fb-4148-9a5c-1e47c6514bcf', path = 'C:\Users\nuras\CS_Projects\miras\farmer_market\flutter\..\backend\uploaded_images\13afcc89-36fb-4148-9a5c-1e47c6514bcf' (OS Error: The filename, directory name, or volume label syntax is incorrect., 
errno = 123)


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Users\nuras\dev\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* 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 5s
Running Gradle task 'assembleDebug'...                    

问题推测

  • 路径解析时正斜杠与反斜杠的兼容性问题
  • ../ 导致路径混乱:构建时路径跳出了flutter_assets目录,引发语法错误

求助需求

有没有办法无冲突地引用Flutter项目外部的文件夹?

已确认:移除yaml文件中的该资源配置后应用恢复正常,问题根源在该资源配置上。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 20:22:34