Flutter: Build errors for cloud_firestore: above version "0.7.4"

7,138

Solution 1

It's not working because it is creating a gradle conflict. Version 0.7.3 of firestore is working because gradle tooling is updated at that version. Please refer changelog and also refer this answer for any other working versions of firebase products.

Solution 2

I feel you, I've also spent hours and hours trying to figure this out.

After building a SSCCE, and then applying the settings of that project to my project, and then some tweaking, I got my project working.

Although I adjusted more settings than I care to remember, these seem to have had the highest impact:

In pubspec.yaml:

# included two other common libraries others might use
cloud_firestore: 0.8.2+1
firebase_auth: 0.7.0
google_sign_in: 3.2.4

Explicitly disable these two features in android/gradle.properties :

android.useAndroidX=false
android.enableJetifier=false

Use these versions of dependencies in android/build.grade:

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath 'com.google.gms:google-services:4.2.0'
}

And finally, use these settings in android/app/build.gradle:

android {
    compileSdkVersion 27
    ...
    defaultConfig {
        ...
        minSdkVersion 21
        targetSdkVersion 28
        multiDexEnabled true
        ...
    }
    ...
}
...
dependencies {
    implementation 'com.google.firebase:firebase-core:16.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile 'com.android.support:multidex:1.0.3'
}

It's also worth noting that I downloaded the google-services.json file again (though that didn't have any effect just by itself).

Any combination of these settings might help you.

Solution 3

There is a problem with google-services.json.

In my case, I was in the same situation while coding Firebase for Flutter on Google Codelabs. I put GoogleService-Info.plist in Xcode in the corresponding folder and put google-services.json in the corresponding folder in Adndroid Studio as well. iOS Simulator worked, but in Android Studio the window like the one below is displayed, then pressing the OK button and launching Android Emulator resulted in the corresponding error.

When coding from scratch and inserting the google-services.json file from the Finder instead of Android Studio, no error occurred.

Android Studio Window1 Android Studio Window2

Share:
7,138
LiveRock
Author by

LiveRock

Updated on December 07, 2022

Comments

  • LiveRock
    LiveRock over 1 year

    I have been trying to resolve a build issue for hours until I realise it is due to Flutter plugin cloud_firestore. Version 0.7.4 builds fine for both Android and iOS but anything above 0.7.4 like 0.8.2+1 will have errors such as:

    CloudFirestorePlugin.java:160: error: cannot find symbol query = query.whereArrayContains(fieldName, value); ^ symbol: method whereArrayContains(String,Object) location: variable query of type Query /dev/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.2+1/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:598: error: cannot find symbol builder.setTimestampsInSnapshotsEnabled( ^ symbol: method setTimestampsInSnapshotsEnabled(Boolean) location: variable builder of type Builder /dev/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.2+1/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:678: error: cannot find symbol return FieldValue.arrayUnion(toArray(readValue(buffer))); ^ symbol: method arrayUnion(Object[]) location: class FieldValue /dev/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.2+1/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:680: error: cannot find symbol return FieldValue.arrayRemove(toArray(readValue(buffer))); ^ symbol: method arrayRemove(Object[]) location: class FieldValue Note: /Users/peterlumdev/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.2+1/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 4 errors FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':cloud_firestore:compileDebugJavaWithJavac'.

    Compilation failed; see the compiler error output for details. * 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 11s Gradle task assembleDebug failed with exit code 1

    I would like to use 0.8.2+1 cloud_firestore for both ios and Android because of the support of

    await db.settings(timestampsInSnapshotsEnabled: true);
    

    Appreciate some help here. Many Thanks!