Android emulator does not gain access to authorized api

21 views
Skip to first unread message

AppWorkerKusi via StackOverflow

unread,
Feb 21, 2017, 6:49:06 PM2/21/17
to google-appengin...@googlegroups.com

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("x...@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)

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



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/42380115/android-emulator-does-not-gain-access-to-authorized-api

AppWorkerKusi via StackOverflow

unread,
Feb 22, 2017, 3:19:09 PM2/22/17
to google-appengin...@googlegroups.com

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("x...@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)
Reply all
Reply to author
Forward
0 new messages