Android Studio error in Login Google, use Firebase

0

Hi, I'm new to Android Studio, I'm trying to log in with Google, to get information and work with it. I downloaded the Firebase assistant tools to configure the application.

When I run the application I get a message saying "The application has stopped working"

If I look at the log this is the bug:

2018-11-29 20:29:04.773 11219-11219/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo, PID: 11219
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/api/Api$zzf;
        at com.google.android.gms.auth.api.Auth.<clinit>(Unknown Source:0)
        at com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo.login.Login.onCreate(Login.java:40)
        at android.app.Activity.performCreate(Activity.java:6975)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        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)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.api.Api$zzf" on path: DexPathList[[zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/base.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_resources_apk.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/lib/x86, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.google.android.gms.auth.api.Auth.<clinit>(Unknown Source:0) 
        at com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo.login.Login.onCreate(Login.java:40) 
        at android.app.Activity.performCreate(Activity.java:6975) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6541) 
        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) 
        Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo-VxwZdUA7dpooKHbGqfGyhw==/split_lib_resources_apk.apk
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:353)
        at dalvik.system.DexFile.<init>(DexFile.java:100)
        at dalvik.system.DexFile.<init>(DexFile.java:74)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
        at dalvik.system.DexPathList.<init>(DexPathList.java:157)
2018-11-29 20:29:04.773 11219-11219/com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo E/AndroidRuntime:     at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
        at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:36)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:676)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:709)
        at android.app.LoadedApk.getResources(LoadedApk.java:936)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2242)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5672)
        at android.app.ActivityThread.-wrap1(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
                ... 6 more

The emulator I'm using is API 26. The version that the Google Play Services tells me that the emulator has installed is 14.5.74.

In the Gradle (Project) I have a post:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        //Dependencia de Google Services
        classpath 'com.google.gms:google-services:4.0.1'
        //classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

On the Gradle (Module):

 android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.jose_antonio_martin_alvarez.agenda_de_bolsillo"
        minSdkVersion 23
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:27.1.1'

    //Dependencia para autenticar con Google
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.3'
    implementation 'com.google.android.gms:play-services-auth:12.0.1'
}

//Dependencia Google Service
apply plugin: 'com.google.gms.google-services'

The class that controls the events of that login button is Login.java:

public class Login extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener {

    private GoogleApiClient clienteGoogle;
    private SignInButton botonInicio;
    //Constante con el valor de cliente
    public static final int CDGO_INI_SESION = 444;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_activity);

        //Objeto de opciones que dice como autenticarlos
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
                /*Metodo que pide el correo*/
                .requestEmail()
                .build();

        //Le paso el contexto al builder, que es el login
        clienteGoogle = new GoogleApiClient.Builder(this)
                /*Y le pongo el método que permite gestionar el ciclo de vida del clienteGoogle con el del activity
                Primer parametro es el activity, segundo el que se encargara de los errores, en mi caso el activity*/
                .enableAutoManage(this, this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();

        botonInicio = (SignInButton) findViewById(R.id.botonInicio);
        botonInicio.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Abre el inicio de sesion
                Intent intent = Auth.GoogleSignInApi.getSignInIntent(clienteGoogle);
                //Iniciamos el cliente de google y le doy un codigo unico
                startActivityForResult(intent, CDGO_INI_SESION);

            }
        });
    }

    /**
     * Método que se ejecuta cuando sucede algún error en la conexión
     *
     * @param connectionResult
     */
    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

    }

    /**
     * Metodo que le llegan los reslutados, si es el resultado que quiero ejecuta el inicio de sesion
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == CDGO_INI_SESION) {
            GoogleSignInResult resultado = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            handleSignInResult(resultado);
        }
    }

    /**
     * Método que controla el correcto funcionamiento del login. En caso contrario muestra un mensaje.
     * @param resultado
     */
    private void handleSignInResult(GoogleSignInResult resultado) {
        //Si la operacion se hace bien
        if(resultado.isSuccess()){
            //Metodo que abre el activity para mostrar los datos
            goMainScreen();
        }else{
            //Si la operacion falla, muestro un mensaje
            Toast.makeText(this, R.string.error_loggin, Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * Abre el activity con los flags necesarios para que nunca se quede como el anterior a la otra.
     */
    private void goMainScreen(){
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}

Thank you, best regards.

    
asked by José Antonio 28.11.2018 в 16:55
source

0 answers