androidandroid-studiogoogle-drive-api

Android App with Google Drive API stucks after choosing an account. Why?


I'm trying to understand how I can integrate Google Drive API in my Android App(using Android Studio). I have tried the example app that I found here(https://github.com/googleworkspace/android-samples/tree/master/drive/deprecation) but after Google API console configuration my app stucks in an infinite loop when I choose an Account. Why? Where is the problem? I tried also with this(https://youtu.be/5bSEIQYJzKs) tutorial but I have the same problem. Here my build.gradle specific lines:

implementation "androidx.multidex:multidex:2.0.1"
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation ('com.google.apis:google-api-services-drive:v3-rev136-1.25.0')
            {
                exclude group: 'org.apache.httpcomponents'
            }
implementation ('com.google.api-client:google-api-client-android:1.26.0')
            {
                exclude group: 'org.apache.httpcomponents'
            }
implementation 'com.google.http-client:google-http-client-gson:1.26.0'

and here is the version that I use

compileSdkVersion 30
buildToolsVersion "30.0.3"

The problem is in this code lines, and occurs only if I use ".requestScopes(new Scope(DriveScopes.DRIVE_FILE))": if i donot use .requestScopes(new Scope(DriveScopes.DRIVE_FILE))", then code works fine. and user do get logedin

GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(DriveScopes.DRIVE_FILE))
                .requestEmail()
                .build();
GoogleSignInClient client= GoogleSignIn.getClient(this,signInOptions);
Intent i= client.getSignInIntent();
startActivityForResult(i,400);

(it seems like the activity never returns any value). Without ".requestScopes(new Scope(DriveScopes.DRIVE_FILE))" the auth request is successful. Here my Google console configuration: The client ID (sorry, maybe it will appear as a link but stackOverflow tell me that I can't put img) and ".../auth/drive.file" is the authorization that I request in google Consent window that appears to the user. I don't know if it is important to say but I use a real phone and not the Android Studio emulator to test my app.


Solution

  • I just solved it. For all those who encounter this problem: from the Google API console, remove the consent screen from the test state and publish it.