Skip to content

Firebase Database ProGuard Issue #1447

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

Closed
NikiFoD opened this issue Sep 14, 2018 · 23 comments
Closed

Firebase Database ProGuard Issue #1447

NikiFoD opened this issue Sep 14, 2018 · 23 comments
Assignees

Comments

@NikiFoD
Copy link

NikiFoD commented Sep 14, 2018

Steps to reproduce:
Log in anonymously like this:

FirebaseAuth.getInstance().signInAnonymously()
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) 
                            onLoggedIn();                   
                });
    }

where

private void onLoggedIn() {
     FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
     DatabaseReference dataRef = firebaseDatabase.getReference();
}

The second line gives me an exception in 4.2.0, which I never had. Double checked now with same code and 4.1.0 and works fine.

FATAL EXCEPTION: main
    Process: com.ki.kloodin, PID: 25145
    java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.firebase.database.obfuscated.zzae.zza(java.lang.Runnable)' on a null object reference
        at com.google.firebase.database.obfuscated.zzab.zza(com.google.firebase:firebase-database@@16.0.2:276)
        at com.google.firebase.database.obfuscated.zzab.<init>(com.google.firebase:firebase-database@@16.0.2:90)
        at com.google.firebase.database.obfuscated.zzad.zzb(com.google.firebase:firebase-database@@16.0.2:101)
        at com.google.firebase.database.obfuscated.zzad.zza(com.google.firebase:firebase-database@@16.0.2:42)
        at com.google.firebase.database.FirebaseDatabase.zza(com.google.firebase:firebase-database@@16.0.2:357)
        at com.google.firebase.database.FirebaseDatabase.getReference(com.google.firebase:firebase-database@@16.0.2:188)
@samtstern
Copy link
Contributor

@NikiFoD so to be clear, you're getting an exception in this line?

 DatabaseReference dataRef = firebaseDatabase.getReference();

Do you have a direct dependency on firebase-database in your build.gradle? If so, what version is it?

As you can see in our releases we bumped the internal version from 16.0.1 to 16.0.2 so it's possible that there's some ProGuard strangeness going on there. And if there is, you can just override the transitive dependency.

@NikiFoD
Copy link
Author

NikiFoD commented Sep 14, 2018

@samtstern Yes, it's on this line.
I don't have a direct dependency.
I added the direct dependency:
implementation 'com.google.firebase:firebase-database:16.0.1'
and got the same error.

@samtstern
Copy link
Contributor

Can you try:

  // I assume this the FirebaseUI dep that you're using?
  implementation('com.firebaseui:firebase-ui-database:4.2.0') {
     exclude group: 'com.google.firebase', module: 'firebase-database'
  }

  implementation 'com.google.firebase:firebase-database:16.0.1'

@NikiFoD
Copy link
Author

NikiFoD commented Sep 14, 2018

Yeap, it's fine like this!

@samtstern samtstern changed the title Anonymous login bug in 4.2.0 Firebase Database ProGuard Issue Sep 14, 2018
@samtstern
Copy link
Contributor

@NikiFoD thanks for confirming! I changed the issue title, going to see what I can find out.

Could you show me your entire dependencies block so I can try and reproduce in my own project?

@samtstern
Copy link
Contributor

This seems to be the same as this question:
https://stackoverflow.com/questions/52315530/getting-npe-in-firebasedatabase-getreference

@NikiFoD
Copy link
Author

NikiFoD commented Sep 14, 2018

Here you are:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
        transitive = true
    }
    implementation('io.fabric.sdk.android:fabric:1.3.10@aar') {
        transitive = true
    }
    implementation 'io.branch.sdk.android:library:2.+'
    implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.firebase:firebase-perf:16.1.0'
    implementation 'com.google.firebase:firebase-core:16.0.3'
    implementation 'com.google.firebase:firebase-messaging:17.3.1'
    implementation 'com.google.firebase:firebase-invites:16.0.3'
    implementation 'com.firebaseui:firebase-ui-auth:4.2.0'
    implementation ('com.firebaseui:firebase-ui-database:4.2.0'){
        exclude group: 'com.google.firebase', module: 'firebase-database'
    }
    implementation 'com.firebaseui:firebase-ui-storage:4.2.0'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-ads:15.0.1'
    implementation 'com.google.maps.android:android-maps-utils:0.5'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'
}

@samtstern
Copy link
Contributor

@NikiFoD thank you! Do you mind also telling me what sort of device you're testing on (Model and OS version)?

@NikiFoD
Copy link
Author

NikiFoD commented Sep 14, 2018

@samtstern Emulator, Nexus 5x, Api 27

Name: Nexus_5X_API_27 CPU/ABI: Google Play Intel Atom (x86) Path: C:\Users\NikiFo.android\avd\Nexus_5X_API_27.avd Target: google_apis_playstore [Google Play] (API level 27) Skin: 1080x1920 SD Card: 100M hw.dPad: no hw.lcd.height: 1920 runtime.network.speed: full hw.accelerometer: yes hw.device.name: Nexus 5X vm.heapSize: 256 skin.dynamic: yes hw.device.manufacturer: Google hw.lcd.width: 1080 hw.gps: yes hw.initialOrientation: Portrait skin.path.backup: _no_skin image.androidVersion.api: 27 hw.audioInput: yes image.sysdir.1: system-images\android-27\google_apis_playstore\x86\ tag.id: google_apis_playstore showDeviceFrame: no hw.camera.back: virtualscene hw.mainKeys: no AvdId: Nexus_5X_API_27 hw.camera.front: emulated hw.lcd.density: 420 avd.ini.displayname: Nexus 5X API 27 hw.arc: false hw.gpu.mode: auto hw.device.hash2: MD5:bc5032b2a871da511332401af3ac6bb0 hw.ramSize: 1536 hw.trackBall: no PlayStore.enabled: true fastboot.forceColdBoot: no hw.battery: yes hw.cpu.ncore: 2 hw.sdCard: yes tag.display: Google Play runtime.network.latency: none hw.keyboard: yes hw.sensors.proximity: yes disk.dataPartition.size: 2G hw.sensors.orientation: yes avd.ini.encoding: UTF-8 hw.gpu.enabled: yes

@samtstern
Copy link
Contributor

@NikiFoD I hate to ask you for more information (I really should slow down and think of all of the questions at once) but could you send a more complete logcat output? We're looking to see if there was maybe another exception that occurred before this one and interfered with SDK initialization.

Bonus points if you can call FirebaseDatabase.getInstance().setLogLevel(Logger.Level.DEBUG); before.

@NikiFoD
Copy link
Author

NikiFoD commented Sep 14, 2018

@samtstern No worries :) The exception is not shown after I put the debug level, although it did crash...
If you need anything else, tell me.

logcat.txt

@samtstern
Copy link
Contributor

Huh it seems like that log is only FA-SVC or FA logs, which come from Google Analytics for Firebase. Did you maybe run adb logcat -s FA FA-SVC by accident?

Ideal would be:

  1. Run adb logcat > logcat.txt
  2. Reproduce the error on the device
  3. Stop the logcat command, send that file over

Which I expect is what you did but I would expect many other logs from the app and system to show up.

@NikiFoD
Copy link
Author

NikiFoD commented Sep 14, 2018

Sorry about that, this one should be correct.
logcat.txt

@schmidt-sebastian schmidt-sebastian self-assigned this Sep 17, 2018
@samtstern
Copy link
Contributor

@NikiFoD I am trying to reproduce this as closely as possible, but can't get it to crash:
https://gist.github.com/samtstern/c8633dd03cd050699e436ece5334b61b

@schmidt-sebastian
Copy link

For reference, this is the line that is crashing: https://github.com/firebase/firebase-android-sdk/blob/00d46269f1ef9ce0f1dd69ab727137a84332d85c/firebase-database/src/main/java/com/google/firebase/database/core/Repo.java#L276

I am still having some trouble piecing together why this is crashing for you. @NikiFoD, can you confirm whether you are calling .getReference() from the main thread?

@NikiFoD
Copy link
Author

NikiFoD commented Sep 18, 2018

Hi @schmidt-sebastian, yes I am calling it from the main thread. Let me try to reproduce it from @samtstern 's gist and I will come back to you

@NikiFoD
Copy link
Author

NikiFoD commented Sep 20, 2018

@samtstern @schmidt-sebastian Finally found it!

The FirebaseMessagingService is causing me the issue. So, to reproduce, add:

  1. Manifest:
<service android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
</service>
  1. MyFirebaseMessagingService.class
public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onNewToken(String token) {

        try{
            DatabaseReference fRef = FirebaseDatabase.getInstance().getReference();
            //  I am getting the reference to write the token in firebase database like:
            // fRef.child("token").setValue(token);
        } catch (Exception e) {
            Log.d("MyFirebaseMsgService", e.getStackTrace().toString());
        }
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

    }
}

In firebase-database 16.0.2, the line DatabaseReference fRef = FirebaseDatabase.getInstance().getReference(); is firing an exception:
Can't create handler inside thread that has not called Looper.prepare()
whereas in 16.0.1 it wasn't.
When this exception is fired, the next firebaseDatabase.getReference() is crashing with the exception described initially.

  1. Dependencies:
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.firebase:firebase-core:16.0.3'
    implementation 'com.google.firebase:firebase-messaging:17.3.1'
    implementation 'com.google.firebase:firebase-invites:16.0.3'
    implementation 'com.firebaseui:firebase-ui-auth:4.2.0'

    implementation 'com.firebaseui:firebase-ui-database:4.2.0'
//    implementation('com.firebaseui:firebase-ui-database:4.2.0') {
//        exclude group: 'com.google.firebase', module: 'firebase-database'
//    }
//    implementation 'com.google.firebase:firebase-database:16.0.1'
}

@schmidt-sebastian
Copy link

Nice! I am glad you were able to find the root cause. Note that we have fixed the error you were seeing ("Can't create handler inside thread that has not called Looper.prepare()") in firebase/firebase-android-sdk#22. This will be released shortly.

I am closing this for now.

@ishaangarg
Copy link

I downgraded firebase-ui-database from 4.2.0 to 4.1.0 and the problem went away

@ReguloSarmiento
Copy link

Hi @schmidt-sebastian, was this released already? I'm using firebase-ui-database:4.2.0 and I got the same error. I don't have a direct dependency for firebase-database :16.0.2. I'm planning to use firebase-database :16.0.3, but I'm not sure If that could cause issues.

@schmidt-sebastian
Copy link

You can manually upgrade to 16.0.3 Please see the instructions here: https://github.com/firebase/FirebaseUI-Android#realtime-database

@bishwajeetbiswas
Copy link

Uncaught exception in Firebase Database runloop (3.0.0). Please report to [email protected]
com.google.firebase.database.obfuscated.zzb$1$1.run

@bishwajeetbiswas
Copy link

Worked after updating to latest version implementation "com.google.firebase:firebase-database:19.3.1"

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

No branches or pull requests

6 participants