1

Below is the fatal error that I keep getting on my App. I am trying to run a chat messenger feature on my application using Firebase. It was running however it has since kept crashing the app entirely. I've made a few edits to the code in the hope of resolving the issues, but to no avail.

I've been following this tutorial on youtbe https://www.youtube.com/watch?v=Xn0tQHpMDnM and it appears by reading the comments that no one else has a similiar error to me.

According to the log, the errors are found on line 99 - displayChatMessage(); as well as on Line 109 - adapter = new FirebaseListAdapter<ChatMessage>(this,ChatMessage.class,R.layout.chat_list_item,FirebaseDatabase.getInstance().getReference()) {

I'm hoping this maybe just a simple code error which I have created, or is it possible it could be to do with my gradle build. Below is the error log I am getting.

FATAL EXCEPTION: main
                                                                                     Process: com.example.aids.a09application, PID: 30713
                                                                                     java.lang.NoSuchMethodError: No virtual method zzEq()Z in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/com.example.aids.a09application-2/split_lib_dependencies_apk.apk:classes33.dex)
                                                                                         at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
                                                                                         at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
                                                                                         at com.example.aids.a09application.MainChatActivity.displayChatMessage(MainChatActivity.java:109)
                                                                                         at com.example.aids.a09application.MainChatActivity.onCreate(MainChatActivity.java:99)
                                                                                         at android.app.Activity.performCreate(Activity.java:6912)
                                                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
                                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)
                                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
                                                                                         at android.app.ActivityThread.-wrap14(ActivityThread.java)
                                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                         at android.os.Looper.loop(Looper.java:154)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:6692)
                                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

Below is the MainActivity Class for the chat messenger in my application:

package com.example.aids.a09application;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.text.format.DateFormat;

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.database.FirebaseListAdapter;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.FirebaseDatabase;

/**
 * Created by Aids on 29/08/2017.
 */

public class MainChatActivity extends AppCompatActivity {

    private static int SIGN_IN_REQUEST_CODE = 1;
    private FirebaseListAdapter<ChatMessage> adapter;
    RelativeLayout chat_activity_main;
    FloatingActionButton fab;

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == (R.id.menu_signout))
        {
            AuthUI.getInstance().signOut( this ).addOnCompleteListener( new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    Snackbar.make( chat_activity_main, "You have been signed out.", Snackbar.LENGTH_SHORT).show();
                    finish();

                }
            } );
        }
        return true;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate( R.menu.chat_main_menu, menu );
        return true;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult( requestCode, resultCode, data );
        if (requestCode == SIGN_IN_REQUEST_CODE)
        {
            if(resultCode == RESULT_OK)
            {
                Snackbar.make( chat_activity_main, "Succesfully signed in. Welcome!", Snackbar.LENGTH_SHORT).show();
                displayChatMessage();
            }
            else {
                Snackbar.make( chat_activity_main, "We couldn't sign you in. Please try again!", Snackbar.LENGTH_SHORT).show();
                finish();
            }
        }
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.chat_activity_main );

        chat_activity_main = (RelativeLayout) findViewById( R.id.chat_activity_main );
        fab = (FloatingActionButton) findViewById( R.id.fab );
        fab.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EditText input = (EditText)findViewById( R.id.input );
                FirebaseDatabase.getInstance().getReference().push().setValue( new ChatMessage(input.getText().toString(),
                        FirebaseAuth.getInstance().getCurrentUser().getEmail()));
                input.setText( "" );

            }
        } );

        if (FirebaseAuth.getInstance().getCurrentUser() == null) {
            startActivityForResult( AuthUI.getInstance().createSignInIntentBuilder().build(), SIGN_IN_REQUEST_CODE );
        } else {
            Snackbar.make( chat_activity_main, "Welcome" + FirebaseAuth.getInstance().getCurrentUser().getEmail(), Snackbar.LENGTH_SHORT ).show();
            //Load Content
            displayChatMessage();
        }



    }

    private void displayChatMessage() {

        ListView listofMessage = (ListView) findViewById( R.id.list_of_messages );
        adapter = new FirebaseListAdapter<ChatMessage>(this,ChatMessage.class,R.layout.chat_list_item,FirebaseDatabase.getInstance().getReference()) {
            @Override
            protected void populateView(View v, ChatMessage model, int position) {
                //Get references to the views of chat_list_item.xml

                TextView messageText, messageUser, messageTime;
                messageText = (TextView) v.findViewById( R.id.message_text );
                messageUser = (TextView) v.findViewById( R.id.message_user );
                messageTime = (TextView) v.findViewById( R.id.message_time );

                messageText.setText( model.getMessageText() );
                messageUser.setText( model.getMessageUser() );
                messageTime.setText( DateFormat.format( "dd-mm-yyyy (HH:MM:SS)",model.getMessageTime() ) );
            }
        };

        listofMessage.setAdapter( adapter );

    }

}

Gradle Build Module:App

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.example.aids.a09application"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        aaptOptions.cruncherEnabled = false
        aaptOptions.useNewCruncher = false

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
android {
    useLibrary 'org.apache.http.legacy'
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })


    compile 'com.google.firebase:firebase-core:11.2.0'
    compile 'com.google.firebase:firebase-messaging:11.2.0'
    compile 'com.android.support:appcompat-v7:26.0.1'
    compile 'com.google.android.gms:play-services-maps:11.2.0'
    compile 'com.google.firebase:firebase-auth:11.2.0' // ADDED
    compile 'com.google.android.gms:play-services-auth:11.2.0' // ADDED
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:26.0.1'
    compile 'com.android.support:support-v4:26.0.1'
    compile 'com.android.support:recyclerview-v7:26.0.1'
    compile 'com.firebaseui:firebase-ui-auth:2.3.0'
    compile 'com.firebaseui:firebase-ui:2.3.0'
}
apply plugin: 'com.google.gms.google-services'
user8534232
  • 57
  • 2
  • 8
  • `or is it possible it could be to do with my gradle build` - well we'd need to see that as well? Also this is a direct pull from this repo - https://github.com/eddydn/ChatApp ? – Mark Aug 29 '17 at 23:45
  • no not a direct Pull, similiar but not the same. – user8534232 Aug 29 '17 at 23:46
  • I see, does a direct clone build? – Mark Aug 29 '17 at 23:48
  • no, the direct clone doesn't build as that ChatApp on GitHub had custom imports, that kept throwing compile errors. – user8534232 Aug 29 '17 at 23:49
  • .. strange just cloned and built fine .. I think `compile 'com.firebaseui:firebase-ui:2.3.0'` contains `core` and a load of other firebase dependencies, so you probably have a transitive problem - try removing everything other than `compile 'com.firebaseui:firebase-ui:2.3.0'` for firebase - I'd suggest looking at your external libraries when you do a gradle sync, it will show all the dependencies you have. – Mark Aug 29 '17 at 23:59
  • Does this new question mean the sync error reported in [your previous question](https://stackoverflow.com/q/45946241/4815718) were resolved? – Bob Snyder Aug 30 '17 at 01:35
  • In your previous question, you were only depending on `firebase-ui-auth`, now you also have `firebase-ui`. Do you need it? If so, additional changes are needed to your dependencies. – Bob Snyder Aug 30 '17 at 01:41
  • I'll try remove the firebase-ui-auth and keep the firebase-ui. I need the core, messaging aspects of Firebase for push notificications. – user8534232 Aug 30 '17 at 14:45
  • /data/app/com.example.aids.a09application-1/split_lib_dependencies_apk.apk:classes32.dex) - I have this in my Logcat. any ideas? – user8534232 Aug 30 '17 at 15:24
  • Anyone able to help - Still not working. Thanks – user8534232 Aug 30 '17 at 16:45

1 Answers1

6

I had a similar problem while reading/writing to firebase database this small change worked for me. Try removing unnecessary firebase dependencies and make sure you use the same version for all the firebase dependencies for those that you use. In my case I changed my firebase dependencies from:

implementation 'com.google.firebase:firebase-firestore:11.8.0'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.0'

to these:

implementation 'com.google.firebase:firebase-firestore:11.8.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-core:11.8.0'

I'm sure you might have spent a lot of time trying to fix this. Might as well turn out worth a shot :)

Shivam Negi
  • 373
  • 5
  • 9