0

The Android Emulator (Nexus) in Android Studio does not gain access to authorized api (Endpoints from Google cloud App Engine). The following code works fine with a physical device but not with the emulator:

credential = GoogleAccountCredential.usingAudience(context,
                        "server:client_id:" + "xyz-xyz.apps.googleusercontent.com");
                credential.setSelectedAccountName("xyz@gmail.com");

                builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(), new
                        AndroidJsonFactory(), credential).setRootUrl("https://babydo-xyz.appspot" +
                        ".com/_ah/api/").setApplicationName("BackendTest");

The following error shows the Android Monitor:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
              Process: ch.appfactory.kusi.backendtest, PID: 8074
              java.lang.RuntimeException: An error occured while executing doInBackground()
                  at android.os.AsyncTask$3.done(AsyncTask.java:300)
                  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
                  at java.util.concurrent.FutureTask.setException(FutureTask.java:222)

Caused by: java.lang.IllegalArgumentException: the name must not be empty: null
                                                                              at android.accounts.Account.<init>(Account.java:48)
                                                                              at com.google.android.gms.auth.zzd.getToken(Unknown Source)
                                                                              at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)

The App Engine console shows no server error.

Interestingly, the emulator has access to the api and work fine, when no authentication is implemented, according to the following Code:

builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(), new
                        AndroidJsonFactory(), null).setRootUrl("https://babydo-xyz.appspot" +
                        ".com/_ah/api/");

Does anyone know what to consider, when the emulator make authenticated calls?

Thanks for answering

KusiTec
  • 23
  • 6
  • Is there another exception listed as the cause for the AsyncTask failure? – Eric O'Connell Feb 22 '17 at 18:29
  • Thanks @Eric O'Connell, I added: Caused by .... – KusiTec Feb 22 '17 at 20:18
  • This may be a case of missing permissions: http://stackoverflow.com/questions/33085685/googleaccountcredential-name-is-null-despite-calling-setselectedaccountname-and – Eric O'Connell Feb 22 '17 at 21:07
  • The permissions are already declared in the manifest (API 22). The example above works with the physical device like Samsung Android mobile but not with the Nexus emulator (API22) on Android Studio... – KusiTec Feb 22 '17 at 22:32

0 Answers0