Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirestoreRecyclerAdapter no virtual method getDocument #1210

Closed
jvergers opened this issue Mar 25, 2018 · 12 comments
Closed

FirestoreRecyclerAdapter no virtual method getDocument #1210

jvergers opened this issue Mar 25, 2018 · 12 comments

Comments

@jvergers
Copy link

I am currently converting my Firebase UI components to Firestore UI components. When building the FirestoreRecyclerAdapter and manually call the adapter.startListening() or initialize it via new FirestoreRecyclerOptions.Builder().setLifeCycleOwner() I stumble on the following fatal exception.

FATAL EXCEPTION: main
Process: packagename, PID: 3129
java.lang.NoSuchMethodError: No virtual method getDocument()Lcom/google/firebase/firestore/DocumentSnapshot; in class Lcom/google/firebase/firestore/DocumentChange; or its super classes (declaration of 'com.google.firebase.firestore.DocumentChange' appears in /data/app/packagename-yHh4aIRPAZwxxRYgunJivQ==/split_lib_dependencies_apk.apk)
at com.firebase.ui.firestore.FirestoreArray.onDocumentAdded(FirestoreArray.java:98)
at com.firebase.ui.firestore.FirestoreArray.onEvent(FirestoreArray.java:83)
at com.firebase.ui.firestore.FirestoreArray.onEvent(FirestoreArray.java:21)
at com.google.firebase.firestore.zzi.onEvent(Unknown Source:17)
at com.google.android.gms.internal.zzeyn.zza(Unknown Source:6)
at com.google.android.gms.internal.zzeyo.run(Unknown Source:6)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

The error states that the class DocumentSnapshot doesn't contain a method getDocument which after checking is correct. However this is also how the docs states this implementation.

The adapter with query

mRecyclerView = (RecyclerView) view;
            mRecyclerView.setLayoutManager(new LinearLayoutManager(context));

            Query query = mFirestore.collection("spots");
            FirestoreRecyclerOptions<SpotModel> options = new FirestoreRecyclerOptions.Builder<SpotModel>().setQuery(query, SpotModel.class).setLifecycleOwner(this).build();

            mAdapter = new FirestoreRecyclerAdapter<SpotModel, SpotHolder>(options) {
                @Override
                public SpotHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_spot, parent, false);

                    return new SpotHolder(view);
                }

                @Override
                protected void onBindViewHolder(@NonNull SpotHolder holder, int position, @NonNull SpotModel model) {
                    holder.bind(model);
                }
            };

            mRecyclerView.setAdapter(mAdapter);

FirebaseUI dependencies

implementation 'com.firebaseui:firebase-ui-auth:3.2.2'
implementation 'com.firebaseui:firebase-ui-database:3.2.2'
implementation 'com.firebaseui:firebase-ui-firestore:3.2.2'

The adapter is being initialized in the onCreateView method of a fragment.

@SUPERCILEX
Copy link
Collaborator

Could post the output of ./gradlew dependencies?

@jvergers
Copy link
Author

jvergers commented Mar 25, 2018

Full output:

Configure project :app
Could not find google-services.json while looking in [src/nullnull/debug, src/debug/nullnull, src/nullnull, src/debug, src/nullnullDebug]
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
Could not find google-services.json while looking in [src/nullnull/release, src/release/nullnull, src/nullnull, src/release, src/nullnullRelease]
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)

Task :dependencies


Root project

No configurations

BUILD SUCCESSFUL in 2s
1 actionable task: 1 executed

Double checked if google-services.json is missing but it's placed in the projects app folder.

@SUPERCILEX
Copy link
Collaborator

Oh, my B. Could you run ./gradlew app:dependencies? Thanks!

@jvergers
Copy link
Author

Attached in textfile since its a pretty big output.

gradeOutput.txt

@SUPERCILEX
Copy link
Collaborator

Huh, your dependencies look good to me. Are you using multidex?

@jvergers
Copy link
Author

Multidex is not enabled.

@samtstern
Copy link
Contributor

@jvergers thank you for this report, I got someone who mentioned this to me directly via email so it appears this is a real issue.

With the other report, it seems the problem comes from mixing Firebase dependencies 12.0.0 and FirebaseUI 3.2.2. You can solve this temporarily by downgrading to 11.8.0. We have a version 12.0.1 coming out in the next few days to fix some packaging issues with 12.0.0 that I hope will resolve this.

@samtstern
Copy link
Contributor

The more I look at it, I also think this could be related to the newly added QueryDocumentSnapshot class in 12.0.0 which is meant to use the type system to signal to the developer that .exists() will always be true for DocumentSnapshot returned from a QuerySnapshot whereas that's not the case if you just call get() on a random DocumentReference

@jvergers
Copy link
Author

Downgrading Firebase to 11.8.0 worked as a temporarily work around, will keep an eye on the update. Thanks a million!

samtstern added a commit that referenced this issue Mar 26, 2018
Change-Id: I411900f48c7402a9b13a4ac89d7abd25aa2bdaf4
@samtstern samtstern added this to the 3.3.0 milestone Mar 26, 2018
@samtstern
Copy link
Contributor

@jvergers I have #1216 to double-fix this issue :-)

I also suspect this is just due to some gradle build caching not being happy when you upgraded from 11.8.0 to 12.0.0, but it should be fixed in a few days either way.

@PankajSavaliya
Copy link

This issue generated by proguard-rules. need to proguard-rules for that issue.

@samtstern
Copy link
Contributor

This issue has been fixed and released in 3.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants