Dart错误:错误:当前Dart运行时不支持dart:mirrors的导入 [英] Dart Error: error: import of dart:mirrors is not supported in the current Dart runtime

查看:1326
本文介绍了Dart错误:错误:当前Dart运行时不支持dart:mirrors的导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用Flutter编写一些移动代码。我正在尝试使用gcloud库dart将数据发布/订阅到GCP Cloud Pub / Sub。以下是main.dart的代码:

  import‘dart:io’; 
作为 auth导入 package:googleapis_auth / auth_io.dart;
导入 package:http / http.dart为http;
导入 package:gcloud / db.dart;
import‘package:gcloud / storage.dart’;


导入 package:gcloud / pubsub.dart;
导入 package:gcloud / service_scope.dart为ss;
导入 package:gcloud / src / datastore_impl.dart作为datastore_impl;

Future< int> main()async {

//从文件中读取服务帐户凭据。
var jsonCredentials = new File(’path / file.json’)。readAsStringSync();
var凭证=新的auth.ServiceAccountCredentials.fromJson(jsonCredentials);

//使用服务帐户凭据获取经过HTTP身份验证的客户端。
var范围= []
..addAll(PubSub.SCOPES);
var client = await auth.clientViaServiceAccount(凭证,作用域);


//实例化对象以访问Cloud Datastore,Cloud Storage
//和Cloud Pub / Sub API。
var pubsub = new PubSub(client,'project-name');
ss.fork((){
//在新服务范围中注册服务
registerPubSubService(pubsub);

//使用这些服务运行应用程序。
});

var topic = await pubsub.createTopic('flutter');
等待topic.publishString('coba publish dr flutter');

var订阅=
等待pubsub.createSubscription('sub_flutter','flutter');
var pullEvent =等待subscription.pull();
print(pullEvent.message.asString);
等待pullEvent.acknowledge();

返回0;
}

这是pubspec.yaml上的依赖项:

 依赖性:
抖动:
sdk:抖动

googleapis:^ 0.54.0
googleapis_beta:^ 0.49.0
googleapis_auth:^ 0.2.10
gcloud:^ 0.6.3

尝试调试代码时,出现以下错误:

 启动lib\ vivo 1918上的main.dart在调试模式下... 
构建build\app\outputsapk\debug\app-debug.apk。
E / flutter(20586):[错误:flutter / shell / common / shell.cc(178)] Dart错误:错误:当前Dart运行时中不支持dart:mirrors的导入/ flutter(20586):[错误:flutter / shell / common / engine.cc(188)]无法准备运行隔离。
E / flutter(20586):[错误:flutter / shell / common / engine.cc(127)]引擎未准备好并启动隔离。
E / flutter(20586):[错误:flutter / shell / common / shell.cc(407)]无法使用配置启动引擎。


解决方案

不幸的是dart的glcoud软件包与flutter不兼容(或网络)由于使用了镜像包。
https://github.com/dart-lang/gcloud/issues/新建



我还可以检查 googleapis 包,其中包含可能符合您需求的pub / sub实现。
https:// pub.dev/documentation/googleapis/latest/googleapis.pubsub.v1/googleapis.pubsub.v1-library.html 。 (由glcoud软件包使用)


I'm currently trying to make some mobile code with Flutter. I'm trying to publish/subscribe data to GCP Cloud Pub/Sub using gcloud library dart. Here is the code for the main.dart:

import 'dart:io';
import 'package:googleapis_auth/auth_io.dart' as auth;
import 'package:http/http.dart' as http;
import 'package:gcloud/db.dart';
import 'package:gcloud/storage.dart';


import 'package:gcloud/pubsub.dart';
import 'package:gcloud/service_scope.dart' as ss;
import 'package:gcloud/src/datastore_impl.dart' as datastore_impl;

Future<int> main() async {

  // Read the service account credentials from the file.
var jsonCredentials = new File('path/file.json').readAsStringSync();
var credentials = new auth.ServiceAccountCredentials.fromJson(jsonCredentials);

// Get an HTTP authenticated client using the service account credentials.
var scopes = []    
    ..addAll(PubSub.SCOPES);
var client = await auth.clientViaServiceAccount(credentials, scopes);


// Instantiate objects to access Cloud Datastore, Cloud Storage
// and Cloud Pub/Sub APIs.
var pubsub = new PubSub(client, 'project-name');
ss.fork(() {
  // register the services in the new service scope.
  registerPubSubService(pubsub);

  // Run application using these services.
});

var topic = await pubsub.createTopic('flutter');
await topic.publishString('coba publish dr flutter');

var subscription =
    await pubsub.createSubscription('sub_flutter', 'flutter');
var pullEvent = await subscription.pull();
print(pullEvent.message.asString);
await pullEvent.acknowledge();

  return 0;
}

Here are the denpendencies on the pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter

  googleapis: ^0.54.0
  googleapis_beta: ^0.49.0
  googleapis_auth: ^0.2.10
  gcloud: ^0.6.3

When trying to debug the code I get the following errors:

Launching lib\main.dart on vivo 1918 in debug mode...
Built build\app\outputs\apk\debug\app-debug.apk.
E/flutter (20586): [ERROR:flutter/shell/common/shell.cc(178)] Dart Error: error: import of dart:mirrors is not supported in the current Dart runtime
E/flutter (20586): [ERROR:flutter/shell/common/engine.cc(188)] Could not prepare to run the isolate.
E/flutter (20586): [ERROR:flutter/shell/common/engine.cc(127)] Engine not prepare and launch isolate.
E/flutter (20586): [ERROR:flutter/shell/common/shell.cc(407)] Could not launch engine with configuration.

解决方案

Unfortunately the glcoud package for dart is not compatible with flutter (or web) due to the mirror package.

I suggest you to open an issue on the github repository about supporting gcloud pub/sub on flutter. https://github.com/dart-lang/gcloud/issues/new

I can also check the googleapis package which has a pub/sub implementation that might fit your needs. https://pub.dev/documentation/googleapis/latest/googleapis.pubsub.v1/googleapis.pubsub.v1-library.html. (use by glcoud package)

这篇关于Dart错误:错误:当前Dart运行时不支持dart:mirrors的导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆