Home » Android » firebase – class file for com.google.android.gms.internal.zzanb not found-Exceptionshub

firebase – class file for com.google.android.gms.internal.zzanb not found-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

i’m beginner for android. i faced this kind of problem when i develop a login application using firebase. what kind of problem is this. and how to solve it. can anyone help me?

error: cannot access zzanb
class file for com.google.android.gms.internal.zzanb not found

main activity:

    import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.EmailAuthProvider;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class MainActivity extends AppCompatActivity {
FirebaseAuth mAuth;
    FirebaseAuth.AuthStateListener mAuthListener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mAuth=FirebaseAuth.getInstance();

        mAuthListener=new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user=firebaseAuth.getCurrentUser();
                if(user==null){
                    Log.d("signout",user.getUid());
                }
                else{
                    Log.d("signin",user.getUid());
                }
            }
        };
    }
    @Override
    public void onStart(){
        super.onStart();
        mAuth.addAuthStateListener(mAuthListener);
    }
    @Override
    public void onStop(){
        super.onStop();
        mAuth.removeAuthStateListener(mAuthListener);
    }
    public void Login(View view) {
        EditText email=(EditText)findViewById(R.id.etEmail);
        EditText password=(EditText)findViewById(R.id.etPassword);
        AuthCredential credential= EmailAuthProvider.getCredential(email.getText().toString(),password.getText().toString());
        mAuth.getCurrentUser().linkWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {

            }
        });
    }

    public void SignOut(View view) {
        mAuth.signOut();
    }
}

build:gradle(project):

    buildscript {
    repositories {
        google()
        jcenter()

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build gradle(module):

    apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.example.krushi"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-analytics:17.2.2'
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    implementation 'com.google.firebase:firebase-core:9.6.1'
    implementation 'com.google.firebase:firebase-auth:9.6.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
How to&Answers:

Try replacing the below,

implementation 'com.google.firebase:firebase-core:17.2.2'
implementation 'com.google.firebase:firebase-auth:17.2.2'

Answer:

Some of your Firebase dependencies are very old:

implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.firebase:firebase-core:9.6.1'
implementation 'com.google.firebase:firebase-auth:9.6.1'

You should make sure they are all using the latest versions as shown in the release notes. The release notes also suggest that you should not add firebase-core any more. So, do this instead:

implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.firebase:firebase-auth:19.2.0'