Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

[Major Refactor] Need to split geofire-android and geofire-java into two repos #28

Closed
vijaysimhajoshi opened this issue Jun 15, 2016 · 33 comments · Fixed by #152
Closed
Assignees

Comments

@vijaysimhajoshi
Copy link

vijaysimhajoshi commented Jun 15, 2016

When trying to set the setLocation on the GeoFire object runs into following issue at run time

No virtual method setValue(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/firebase/tasks/Task; in class Lcom/google/firebase/database/DatabaseReference; or its super classes (declaration of 'com.google.firebase.database.DatabaseReference' appears in  (apk file )

Using the GeoFire 2.0.0 SNAPSHOT version.
Firebase version: com.google.firebase:firebase-database:9.0.2

@samtstern
Copy link
Contributor

samtstern commented Jun 28, 2016

@jdimond @AbeHaskins I am seeing this as well when trying to use the geofire-2 branch in an Android app.

The problem is this block in GeoFire.java

        if (completionListener != null) {
            keyRef.setValue(updates, geoHash.getGeoHashString(), new DatabaseReference.CompletionListener() {
                @Override
                public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
                    completionListener.onComplete(key, databaseError);
                }
            });
        } else {
            keyRef.setValue(updates, geoHash.getGeoHashString());
        }

Specifically the crash is at this line:

            keyRef.setValue(updates, geoHash.getGeoHashString());

Full error is:

E/UncaughtException: java.lang.NoSuchMethodError: No virtual method setValue(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/firebase/tasks/Task; in class Lcom/google/firebase/database/DatabaseReference; or its super classes (declaration of 'com.google.firebase.database.DatabaseReference' appears in /data/data/com.google.firebase.example.pageslist/files/instant-run/dex/slice-com.google.firebase-firebase-database-9.0.2_cf1a3e9008757a5e1cc475db32fed25d0175f77f-classes.dex)
                                                          at com.firebase.geofire.GeoFire.setLocation(GeoFire.java:178)
                                                          at com.firebase.geofire.GeoFire.setLocation(GeoFire.java:150)

@samtstern
Copy link
Contributor

Fixed be #34

@MrIceman
Copy link

MrIceman commented May 7, 2017

any fix yet?

@orzsikodon
Copy link

orzsikodon commented Feb 11, 2018

hi, so it appears that this bug only manifests itself when we call setLocation without the GeoFire.CompletionListener().

If you call geoFire.setLocation("X marks the spot", new GeoLocation(x, y), new GeoFire.CompletionListener() { } then it works. (Im using geofire 2.3.0)

@andronicus-kim
Copy link

@orzsikodon Hi, i added the Completion listener but i still run into the same bug.

@horgag1
Copy link

horgag1 commented Mar 6, 2018

any update on this?

Version 2.1.1 works fine.

@samtstern samtstern reopened this Mar 6, 2018
@habeebrahmanpt
Copy link

com.firebase:geofire-android:2.3.0' have this problem

@samtstern
Copy link
Contributor

This looks very similar to #133 ... but I have not been able to reproduce it in a long time so I am not sure how to fix it. If anyone could send along an MCVE that would be amazing.

@samtstern
Copy link
Contributor

@DongNH4 @habeebrahmanpt can you show me your dependencies from app/build.gradle?

@umarhussain15
Copy link

Please see the dependencies list:

    implementation 'com.google.firebase:firebase-core:12.0.1'
    implementation "com.google.firebase:firebase-auth:12.0.1"
    implementation "com.google.firebase:firebase-database:12.0.1"
    implementation "com.google.android.gms:play-services-auth:12.0.1"
    implementation "com.google.android.gms:play-services-maps:12.0.1"
    implementation "com.google.android.gms:play-services-location:12.0.1"
    implementation "com.google.android.gms:play-services-places:12.0.1"
    implementation 'com.firebase:geofire-android:2.3.1'

@samtstern
Copy link
Contributor

@umarhussain15 looks like you updated to 2.3.1 which was released today, are you still seeing this issue? Also does your app use ProGuard?

@umarhussain15
Copy link

Yes still the issue is present with 2.3.1. proguard is set to true in debug

@samtstern
Copy link
Contributor

@umarhussain15 can you try disabling proguard and seeing if the issue persists?

@umarhussain15
Copy link

It still persist. I manually tried the functionality of setLocation that is working fine here is the code snippet:

// working
GeoHash geoHash = new GeoHash(new GeoLocation(location.getLatitude(),location.getLongitude()));
Map<String, Object> updates = new HashMap<>();
updates.put("g", geoHash.getGeoHashString());
updates.put("l", Arrays.asList(location.getLatitude(),location.getLongitude()));
geoFire.getDatabaseReference().child(firebaseUser.getUid()).setValue(updates,geoHash.getGeoHashString());
// not working
//geoFire.setLocation(firebaseUser.getUid(), new GeoLocation(location.getLatitude(),location.getLongitude())); 

I used the firebase reference from geofire just to test if that was the issue but it works when tried manually.

@samtstern
Copy link
Contributor

@umarhussain15 damn ok well thank you for trying! I will have to think about what could be the root cause here.

@vikskod
Copy link

vikskod commented Apr 19, 2018

Today is 4/19/2018 but it has the same problem.
It's so funny if you add GeoFire.CompletionListener then it only works:

geoFire.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
@OverRide
public void onComplete(String key, DatabaseError error) {

        }
    });

@maher640
Copy link

21/04/2018
The error still happening also when removing the location removeLocation(key) and doesn't work unless the listener is provided.

@HusDev
Copy link

HusDev commented May 5, 2018

I change it from com.firebase:geofire-android:3.1.0 to com.firebase:geofire-android:2.1.1
works fine :)

@ashu-mkb
Copy link

This issue is only arising with proguard. But i need to keep proguard to safeguard (somewhat) other logic inside. Please help its very urgent. Also, by downgrading dependency to 2.1.1, geoquery seems to be not working. I am not explicitly using setLocation etc, i am only using geofire to query location. Please help!

@zezulaon
Copy link

@ashu-mkb Perhaps it is related to Proguard removing firebase classes?

-dontwarn com.firebase.** -keep class com.firebase.** { *; } -keep interface com.firebase.** { *; }

https://stackoverflow.com/questions/48463519/cant-find-referenced-method-com-google-firebase-tasks-task-setvaluejava-lang

@ashu-mkb
Copy link

@ZEZI Thank you so much! Though i tried earlier to add exception in proguard, i failed to achieve the desired result. This fixed my problem. Thank you again!!!

jwiesmann pushed a commit to jwiesmann/geofire-java that referenced this issue Sep 1, 2018
…ad of keyRef.setValue also fixes a huge amount of unnecessary 'onDataExited(DataSnapshot dataSnapshot)' events which has not been reported yet. keyRef.updateChildren understands if the data needs to be inserted or updated. No need to use setValue here. Since priorities are not relevant anymore (https://stackoverflow.com/questions/31577915/what-does-priority-mean-in-firebase) i decided to not consider them anymore.
@abelthefirst
Copy link

The problem here is the way GeoFire declares firebase-database dependency. Versions after 2.1.2 use following version declaration (the latest 2.3.1, for instance): <version>12.0.1</version>. For the given version of the firebase-database setValue method is resolved into setValue(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/firebase/tasks/Task;. The actual method signature for the firebase-database dependency in my project (I use the latest 16.0.4) is setValue(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/android/gms/tasks/Task;. Note, that the return type is different, that's the reason of the NoSuchMethodError.

@Dilshan97
Copy link

I change it from com.firebase:geofire-android:3.1.0 to com.firebase:geofire-android:2.1.1
works fine :)

Yeah it's works for me :-) Thank you

@samtstern
Copy link
Contributor

Thanks @abelthefirst for laying it out so clearly. This seems to be a fundamental issue with how this library is structured and published. IMO the only way forward would be to make separate geofire-java and geofire-android libraries (no shared source, maybe a shared published dependency) but that's more effort than I can spare right now :-/

@umarhussain15
Copy link

@samtstern I have extracted the geofire library as library module for android. Its working correctly but I am having difficulty in making test cases successful. My understanding is that you have written test with admin sdk for java. In case of Android I was looking for using android test so that the context is available.
Can you guide on how to convert the test cases for android library?
Here is the link to my repo:
https://github.com/umarhussain15/geofire-android

@Stevemoretz
Copy link

It still doesn't work in 2019.Without the listeners.

@samtstern
Copy link
Contributor

@umarhussain15 wow geofire-android is really cool! Sorry I missed this in my inbox the first time.

I think splitting this up into Android and Java libraries with separate repos is the only way forward, but unfortunately I don't have the time to handle such a big project right now.

As for the test cases I suspect we will have to do something different on Android. Maybe use the regular Android SDK but sign in with a custom token?

@samtstern samtstern changed the title GeoFire.setLocation - No virtual method setValue(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/firebase/tasks/Task; in class Lcom/google/firebase/database/DatabaseReference; or its super classes (declaration of 'com.google.firebase.database.DatabaseReference' [Major Refactor] Need to split geofire-android and geofire-java into two repos Feb 28, 2019
@emailsubjekt
Copy link

@umarhussain15 wow geofire-android is really cool! Sorry I missed this in my inbox the first time.

I think splitting this up into Android and Java libraries with separate repos is the only way forward, but unfortunately I don't have the time to handle such a big project right now.

As for the test cases I suspect we will have to do something different on Android. Maybe use the regular Android SDK but sign in with a custom token?

What are you talking about? Is there still not a solution for this. I keep getting this error from time to time. This can't happen in an app!

@umarhussain15
Copy link

@emailsubjekt please have a look at https://github.com/umarhussain15/geofire-android. I have extracted the library specifically as android module to avoid the issues mention in this thread. It in working state and can be easily plugged in place of geofire-java.

@emailsubjekt
Copy link

@emailsubjekt please have a look at https://github.com/umarhussain15/geofire-android. I have extracted the library specifically as android module to avoid the issues mention in this thread. It in working state and can be easily plugged in place of geofire-java.

Is this official or a workaround?

@samtstern
Copy link
Contributor

@emailsubjekt it's a workaround but I officially recommend it for now! @umarhussain15 has done the right thing.

@samtstern samtstern self-assigned this Jun 11, 2019
@samtstern
Copy link
Contributor

I have finally gotten the time to take this on. I am going to:

  1. Make a new repository called geofire-android that ships an android-only version of this library.
  2. Convert this repository to be java-admin only and remove the android module from here.
  3. Republish both libraries at a new major version.

@emailsubjekt
Copy link

@emailsubjekt please have a look at https://github.com/umarhussain15/geofire-android. I have extracted the library specifically as android module to avoid the issues mention in this thread. It in working state and can be easily plugged in place of geofire-java.

Thanks!

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

Successfully merging a pull request may close this issue.