在我的资产上发现“未找到资产的文件或变体”错误

C.C*_*ana 18 dart android-studio flutter

当我尝试运行我的应用程序时,我收到此附加错误。有任何想法吗?(以下)

Launching lib\main.dart on SM J200Y in debug mode...
Running Gradle task 'assembleDebug'...
? Built build\app\outputs\apk\debug\app-debug.apk.
Error detected in pubspec.yaml:
No file or variants found for asset: assets/credentials.json.
Run Code Online (Sandbox Code Playgroud)

我检查了 yaml 文件,格式似乎没问题。我不知所措。(另外,下面)

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  # To add assets to your application, add an assets section, like this:
  assets:
  - assets/credentials.json
Run Code Online (Sandbox Code Playgroud)

Rav*_*ara 39

就我而言,问题是我缺少 slash /

首先,我添加了我的图标路径,如下所示。

  assets:
      - assets/icons
Run Code Online (Sandbox Code Playgroud)

我通过/在路径末尾添加斜杠来解决这个问题,如下所示:

  assets:
      - assets/icons/
Run Code Online (Sandbox Code Playgroud)


Dar*_*han 18

检查资产标识。通常它应该从新行的开始有 3 个空格。

assets:
 - assets/credentials.json // <-- count three spaces from start
Run Code Online (Sandbox Code Playgroud)


San*_*dal 8

我遇到了同样的问题,我有两个错误:

  1. 我在“lib”文件夹内创建了“images”文件夹,它应该在lib文件夹之外,它应该在应用程序根文件夹中。 在此处输入图片说明

  2. 正如@Darshan 所说,它应该离起始行三个空格

    -assets/credentials.json // <-- 从开始算三个空格

    它应该出现一条灰线,像这样

    在此处输入图片说明


Sha*_*ikh 6

有2种可能性

  1. 项目目录中缺少文件夹/文件
  2. pubspec.yaml文件中的文件夹/文件名末尾缺少“/”