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