Flutter build 给出 .pub-cache cloud firestore 错误
Posted
技术标签:
【中文标题】Flutter build 给出 .pub-cache cloud firestore 错误【英文标题】:Flutter build gives a .pub-cache cloud firestore error 【发布时间】:2021-04-23 18:49:36 【问题描述】:除了尝试使用 Cloud Firestore 运行 StreamBuilder 之外,我不记得有任何更改,然后开始出现以下错误。我评论了 Streambuilder,但没有任何变化。
**我已采取的步骤:
-
运行颤振 pub 缓存修复
跑扑干净
删除了 cloud firestore 包,然后调用 pub get,然后再次添加它并再次运行 pub get。**
包版本: firebase_core:^0.7.0 cloud_firestore: ^0.16.0
颤振: Flutter 1.22.5 • 通道稳定 • https://github.com/flutter/flutter.git 框架 • 修订 7891006299(6 周前) • 2020-12-10 11:54:40 -0800 引擎 • 修订版 ae90085a84 工具 • Dart 2.10.4
错误:
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/collection_reference.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/document_change.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/document_reference.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/document_snapshot.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/field_value.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/firestore.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/query.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/query_document_snapshot.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/query_snapshot.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/snapshot_metadata.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/transaction.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/utils/codec_utility.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/src/write_batch.dart: Error: A file can't be part of more than one library.
Try moving the shared declarations into the libraries, or into a new library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart: Context: Used as a part in this library.
/C:/Users/yassin/Downloads/Programming%20files/Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.16.0/lib/cloud_firestore.dart%20: Context: Used as a part in this library.
FAILURE: Build failed with an exception.
* Where:
Script 'C:\Users\yassin\Downloads\Programming files\Flutter\packages\flutter_tools\gradle\flutter.gradle' line: 904
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Users\yassin\Downloads\Programming files\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 12s
Exception: Gradle task assembleDebug failed with exit code 1
更新 1:当前已评论但我在错误出现之前调用的流。
Future<List<QuerySnapshot>> displayLocations() async
final List<DocumentSnapshot> documents = [];
_firebaseFirestore
.collection('locations')
.get()
.then((QuerySnapshot querySnapshot) =>
querySnapshot.docs.forEach((doc)
documents.add(doc);
return documents;
)
);
@override
Widget build(BuildContext context)
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection('locations').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot)
if (snapshot.hasError)
return Text('Something went wrong');
if (snapshot.connectionState == ConnectionState.waiting)
return Text("Loading");
return ListView(
children: snapshot.data.docs.map((DocumentSnapshot document)
return ListTile(
title: Text(
document.data()['locationName'] ?? 'Unable to retrieve data'),
);
).toList(),
);
,
);
【问题讨论】:
你能告诉我们你的代码吗?您拨打StreamBuilder
的地方。
添加了代码更新。 @Andrej
【参考方案1】:
这里https://github.com/Dart-Code/Dart-Code/issues/2172 提出的对我有用的解决方案是:
1.删除项目中的 .dart_tool 文件
2。转到 pubspec.yaml 并发布获取。
【讨论】:
以上是关于Flutter build 给出 .pub-cache cloud firestore 错误的主要内容,如果未能解决你的问题,请参考以下文章
Xcode build 给出了这个错误:ld: library not found for -lFMDB
Flutter 在执行 Flutter build ios 后卡在 Building Dart 代码上
Flutter:读取 build.yaml 文件中传递给 build_runner 的变量
如何修复 Flutter build_runner 错误:无法预编译 build_runner:build_runner: