0

我正在尝试使用我自己编写的源代码生成包,称为animated_widget_generator. 调用 annotations 包,并调用animated_widget_annotations我尝试使用它的应用程序example_usage

我将必要的包添加到我的dev_dependencies. 这是我的pubspec.yaml

name: example_usage
description: A new Flutter project.

publish_to: 'none'

version: 1.0.0+1

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  animated_widget_generator:
    path: ../animated_widget_generator
  animated_widget_annotations:
    path: ../animated_widget_annotations
  build_runner: ^2.0.4

flutter:
  uses-material-design: true

但是当我尝试在手机上运行该应用程序时,它给了我以下错误:

Launching lib\main.dart on ONEPLUS A6003 in debug mode...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
E/flutter (17052): [ERROR:flutter/shell/common/shell.cc(242)] Dart Error: error: import of dart:mirrors is not supported in the current Dart runtime
E/flutter (17052): [ERROR:flutter/runtime/dart_isolate.cc(169)] Could not prepare isolate.
E/flutter (17052): [ERROR:flutter/runtime/runtime_controller.cc(401)] Could not create root isolate.
E/flutter (17052): [ERROR:flutter/shell/common/shell.cc(571)] Could not launch engine with configuration.
Exited (1)

Stack Overflow 上还有其他关于这个错误的问题,但它们总是关于一些第三方包,而不是关于自定义源生成包,而且这些问题的任何答案似乎都与我无关

编辑:pubspec.yaml对于animated_widget_generatoranimated_widget_annotations

name: animated_widget_annotations
description: A new Flutter package project.
version: 0.0.1
author:
homepage:

environment:
  sdk: ">=2.12.0 <3.0.0"
  flutter: ">=1.17.0"

dependencies:
  flutter:
    sdk: flutter

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:

name: animated_widget_generator
description: A new Flutter package project.
version: 0.0.1
author:
homepage:

environment:
  sdk: ">=2.12.0 <3.0.0"
  flutter: ">=1.17.0"

dependencies:
  flutter:
    sdk: flutter
  path: ^1.8.0
  source_gen: ^1.0.2
  json_serializable: ^4.1.3
  animated_widget_annotations:
    path: ../animated_widget_annotations

dev_dependencies:
  flutter_test:
    sdk: flutter
  pedantic: ^1.11.0
  build_runner: ^2.0.4

flutter:

4

2 回答 2

0

对于即将到来的 Flutter 开发人员来说,这是一个非常常见的问题。主要原因是颤振和飞镖正在快速更新。有时在他们升级之后,比如说在最新版本的 Flutter 2.2 之后,你可以在他们的 github 上看到一些包已从其稳定模式中删除,以便对其进行处理以提高它们的效率。因此,您无法访问这些软件包。确保为同一任务找到替代包,或者尝试将依赖项的版本号更改为较低的数字,这可能由于向后兼容性而起作用。如果您有版本问题,pubspec.yaml 可能很难理解,因为它会告诉您依赖项不存在但不会告诉您原因。

于 2021-06-15T12:37:27.470 回答
0

您收到此错误是因为 packagedart:mirrors包不适用于颤振。

请在google 群组github上查看这些对话以获取更多信息。

一个称为反射的替代包可用于反射,但目前它有局限性。

于 2021-06-15T11:18:10.133 回答