Saturday, July 2, 2016

GoogleAuthException: INVALID_AUDIENCE

I've been having some problems getting an Android app to properly authenticate with my app engine backend. For like weeks, spending the evenings looking through every single google result and trying out different combinations of peoples experience. Today, I finally figured out what my mistake was and I have to write this down.

The problem lies on this page and in this statement.
You need to specify your Android app's package name and SHA1 fingerprint.
  1. In the Package name field, enter your Android app's package name.

This is WRONG! It is in fact the applicationId in the build.gradle file that should be used. The package name in the manifest and the applicationId is most of the time the same, but in my it was not. And I never got the app to properly authenticate. But now it does and I'm happy again!

4 comments:

  1. I am experiencing the same trauma and stuck on INVALID AUDIENCE. I have gone back to the original steps -- including to regenerat the OAuth key. My package (in android manifest) is the same as my applicationId (in gradle build).

    HELP!

    I can't debug or troubleshoot any further. I need suggestions to debug further.

    ReplyDelete
    Replies
    1. You'll have to do what I did. Google and try all the different solutions people have had to this problem. Like regenerating the keystore and such. Also, make sure you get the configuration right in the cloud console. You should use a Web client ID and not an android client ID.

      Delete
  2. OK - I have followed all the other posts -- some dating back to <2013 -- and yours is the most recent that I have found. I think I have tried everything except regenerating the keystore. One question, my applicationId and package are the same. Is that a problem? Should I make them different (aside from forcing the confusion factor to be more distinct). I appreciate the confirmation to use the Web Client ID not the Android. I have tried both and had strong reason to believe that "web" was correct.

    ReplyDelete
    Replies
    1. Sorry for the late reply but yes, they should be the same. They can probably be different but that's just risking more problems.

      Hope it worked it for you!

      Delete