Search code examples
firebasefluttergoogle-cloud-firestoreflutter-dependencies

Flutter build gives a .pub-cache cloud firestore error


I don't recall changing anything besides attempting to run a StreamBuilder using cloud firestore, then this error below started to appear. I commented the Streambuilder but nothing is changing.

**Steps i have taken:

  1. Ran flutter pub cache repair
  2. Ran flutter clean
  3. Removed cloud firestore package then called pub get and then added it again and run pub get once more.**

Packages versions: firebase_core: ^0.7.0 cloud_firestore: ^0.16.0

Flutter: Flutter 1.22.5 • channel stable • https://github.com/flutter/flutter.git Framework • revision 7891006299 (6 weeks ago) • 2020-12-10 11:54:40 -0800 Engine • revision ae90085a84 Tools • Dart 2.10.4

The Error:

/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

UPDATE 1: The streams that are currently commented but i had called before the error appeared.

     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(),
        );
      },
    );
  }

Solution

  • The solution that worked for me as proposed here https://github.com/Dart-Code/Dart-Code/issues/2172 is to:

    1. Delete the .dart_tool file which you'll find inside your project

    2. Go to pubspec.yaml and pub get.