【问题标题】:“Could not resolved the package” every install new packages inside my own package“无法解决包”每次在我自己的包中安装新包
【发布时间】:2020-08-15 09:06:11
【问题描述】:

我在从 pub.dev 安装新软件包时遇到了一些问题。我使用package 拆分我的架构以实现modularization。这是我项目中的packages(核心和共享)。

我使用此命令flutter create --template=package name_of_modules 创建coreshared 模块。

然后我在 coreshared 模块中安装新软件包。每次我在该模块中安装新软件包时,我总是收到如下错误:

Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Invalid depfile: /Users/rrifafauzikomara/Downloads/MovieCatalogue/.dart_tool/flutter_build/009f5ba5376d66cb437ddc8aa8ed1cad/kernel_snapshot.d
Invalid depfile: /Users/rrifafauzikomara/Downloads/MovieCatalogue/.dart_tool/flutter_build/009f5ba5376d66cb437ddc8aa8ed1cad/kernel_snapshot.d

Compiler message:
Error: Could not resolve the package 'json_annotation' in 'package:json_annotation/json_annotation.dart'.
core/lib/src/network/api/rest_client.dart:2:8: Error: Not found: 'package:json_annotation/json_annotation.dart'
import 'package:json_annotation/json_annotation.dart';
       ^
core/lib/src/network/api/rest_client.dart:39:2: Error: Method not found: 'JsonSerializable'.
@JsonSerializable()
 ^^^^^^^^^^^^^^^^
core/lib/src/network/api/rest_client.dart:51:2: Error: Method not found: 'JsonSerializable'.
@JsonSerializable()
 ^^^^^^^^^^^^^^^^
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:package%3Ajson_annotation%2Fjson_annotation.dart; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:33:7)
#1      asFileUri (package:vm/kernel_front_end.dart:604:37)
#2      writeDepfile (package:vm/kernel_front_end.dart:799:21)
<asynchronous suspension>
#3      FrontendCompiler.compile (package:frontend_server/frontend_server.dart:472:15)
<asynchronous suspension>
#4      _FlutterFrontendCompiler.compile (package:flutter_frontend_server/server.dart:38:22)
#5      starter (package:flutter_frontend_server/server.dart:149:27)
#6      main (file:///b/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:8:30)
#7      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:32)
#8      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)

Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
Failed to build bundle.
Error launching application on iPhone 11 Pro Max.

错误的结果总是关于Could not resolved the package,但我可以import这个包,也可以使用这个包。但是在我运行项目之后,它显示的错误。这是 Flutter 的一个错误?以及如何解决?因为我需要这种方法来使我的项目具有可扩展性,并且还需要像 Android 原生那样实现模块化。

这是我flutter doctor -v的结果:

[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.2 19C57,
    locale en-US)
    • Flutter version 1.12.13+hotfix.8 at
      /Users/rrifafauzikomara/Documents/flutter
    • Framework revision 0b8abb4724 (3 months ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/rrifafauzikomara/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.4.1, Build version 11E503a
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build
      1.8.0_212-release-1586-b4-5784211)

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

[✓] Connected device (1 available)
    • iPhone 11 Pro Max • 641006EC-FDB0-4918-B547-593818B98B05 • ios •
      com.apple.CoreSimulator.SimRuntime.iOS-13-4 (simulator)

• No issues found!

【问题讨论】:

  • 我也有同样的问题,无法解决
  • @Nux 请在下面阅读我的回答。

标签: flutter package


【解决方案1】:

我通过“使缓存无效/重新启动...”修复了我的问题enter image description here

【讨论】:

    【解决方案2】:

    我已经修复了我的issue 并将其添加到根项目中。所以我添加了像shimmer 2x 这样的新包,一个在shared 模块中,一个在根项目中。

    并非所有的都必须添加两次,只添加那些导致错误的。

    【讨论】:

    • 你是怎么添加到根项目的?
    猜你喜欢
    • 2020-05-21
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    • 2021-12-01
    • 2018-02-04
    • 1970-01-01
    • 2022-01-22
    • 2019-03-08
    相关资源
    最近更新 更多