Google Authentication in Android Unity Plugin - android
I'm working on an Android application that includes communication with the Amazon S3 servers. The app is being developed in Unity and I would like to include a system so that the users can authenticate with their Google Accounts and then use those credentials to access the S3 server through Cognito. To do that, I need to implement a Google Authenticator system in Unity, and I am having a hard time figuring out how to do it. My current approach consists in creating a Plugin with Android Studio to access the Google Sign In API, but every time I execute the program, it throws a NoClassDefFoundError exception. Here is my logcat:
03-25 20:45:34.968 25581-25610/? D/MainActivity: Authenticating...
03-25 20:45:35.086 25581-25610/? I/Unity: AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/auth/api/signin/GoogleSignInOptions$Builder;
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/auth/api/signin/GoogleSignInOptions$Builder;
at com.unityplugin.MainActivity.authenticate(MainActivity.java:55)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.a(Unknown Source)
at com.unity3d.player.UnityPlayer$b.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.auth.api.signin.GoogleSignInOptions$Builder" on path: DexPathList[[zip file "/data/app/com.unityplugin-2/base.apk"],nativeLibraryDirectories=[/data/app/com.unityplugin-2/lib/arm, /data/app/com.unityplugin-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadCla
Here is the relevant part of my Android code (UnityPlayer Activity):
public void authenticate() {
Log.d(TAG, "Authenticating...");
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
//HERE IS THE ERROR (LINE 55)
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(Constants.GOOGLE_CLIENT_ID)
.requestEmail()
.build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addConnectionCallbacks(new ConnCallBack())
.addOnConnectionFailedListener(new FailedListener())
.build();
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
The code works if I execute it in a native APK inside a Compact Activity, but when I make it into a plugin and run it with Unity, I get the error. In Unity, I call the authenticate() method with this code:
//Get Activity
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
//Call function authenticate
currentActivity.Call("authenticate");
I have tried including the classes.jar file in the com.google.android.gms.play-services-auth-8.4.0 external library that I have in Android Studio, but it didn't work. I have also considered implementing the authentication directly in Unity instead of making a plugin, but all the information that I saw about doing something like that relates to Google Play Games, and I am not interested in including the Google Play Games API in my application, I just want to let the users log in with their Google account so that they can access the S3 server. If anyone has implemented a similar feature with Unity and knows a better way of doing this, I'm all ears. I am open to using a different way to enable Google Authentication in my app, the only requisite is that it has to be done in Unity.
Thanks in advance!
I solved my problem using this code to authenticate the user:
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
String token = GoogleAuthUtil.getToken(getApplicationContext(), accounts[0].name,
"audience:server:client_id:YOUR_GOOGLE_CLIENT_ID");
Map<String, String> logins = new HashMap<String, String>();
logins.put("accounts.google.com", token);
credentialsProvider.setLogins(logins);
Also, I had to add the following libraries in form of JAR files:
android-support-v4
google-play-services
Related
NoClassDefFoundError dependency issues calling Gmail API
I'm trying to access my Gmail from an Android app and am running into dependency issues. I've been following a combination of guides, including the Java Quickstart (https://developers.google.com/gmail/api/quickstart/java) and a few others on StackOverflow and GitHub. Whenever I run the emulator, I get a "NoClassDefFoundError", always from a Google API call to AuthorizationCodeInstalledApp.authorize(). Here's one of them: java.lang.NoClassDefFoundError: Failed resolution of: Lsun/security/action/GetLongAction; at sun.net.httpserver.ServerConfig.<clinit>(ServerConfig.java:43) at sun.net.httpserver.ServerConfig.getClockTick(ServerConfig.java:100) at sun.net.httpserver.ServerImpl.<clinit>(ServerImpl.java:50) at sun.net.httpserver.HttpServerImpl.<init>(HttpServerImpl.java:32) at sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:17) at com.sun.net.httpserver.HttpServer.create(HttpServer.java:111) at com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver.getRedirectUri(LocalServerReceiver.java:127) at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.authorize(AuthorizationCodeInstalledApp.java:108) at com.example.gmailtemplates.ui.templates.TemplateListAdapter.getCredentials(TemplateListAdapter.java:141) Here's my code that calls it, which I literally copied and pasted from a guide: // Build flow and trigger user authorization request. GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES) .setDataStoreFactory(new FileDataStoreFactory(tokenFolder)) .setAccessType("offline") .build(); LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build(); Credential credential = new AuthorizationCodeInstalledApp(flow, receiver).authorize("user"); return credential; My gradle build file includes: repositories { mavenCentral() } dependencies { implementation 'com.google.api-client:google-api-client:1.32.2' implementation 'com.google.oauth-client:google-oauth-client-jetty:1.32.1' implementation 'com.google.apis:google-api-services-gmail:v1-rev20211108-1.32.1' implementation 'com.google.android.gms:play-services-auth:20.0.0' .... } The thing is that I'm pretty sure that sun.net.httpserver is pretty old and no longer used. Am I missing something or using some weird old version of Google API? I'm using Android Studio for the first time, so it's possible that I made some wrong configuration.
"Developer error: this application is misconfigured" Google sign in on firebase with whitelisted client id
I'm trying to migrate to firebase auth on my android app. The package name and SHA1 are currently associated with an old app engine project (which I don't want to upgrade to firebase) and therefore I can't add the SHA1 fingerprint to my new firebase project. The app engine project is currently in production, so I can't remove the android client ids or delete the project. The documentation here https://support.google.com/firebase/answer/6401008?authuser=0 says that I should be able to whitelist the client IDs of the old app engine project. However when I do this and then try to log in to the app with google using firebase auth I get the following error "Developer error: this application is misconfigured. Check your SHA1 and package name in the Firebase console." I have also tried the instructions here https://firebase.googleblog.com/2016/12/working-with-multiple-firebase-projects-in-an-android-app.html which involve passing in a GoogleSignInOptionsobject into the AuthUI builder with a web client id from the appropriate project like so: private void StartLoginActivity() { GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken("<my-client-id>.apps.googleusercontent.com") .requestEmail() .build(); List<AuthUI.IdpConfig> providers = Arrays.asList( new AuthUI.IdpConfig.EmailBuilder().build(), new AuthUI.IdpConfig.GoogleBuilder().setSignInOptions(gso).build()); startActivityForResult( AuthUI.getInstance() .createSignInIntentBuilder() .setAvailableProviders(providers) .build(), RC_SIGN_IN); } but when I do that I get the error java.lang.IllegalArgumentException: two different server client ids provided So my question is how can I configure my firebase project to enable auth when the SHA1 is associated with an existing GCP project?
I got the following response from firebase support and was able to get this working: Google sign in with FirebaseUI is configured through the google-services.json >file. The issue is that if you are using an OAuth client ID from a different >project, the default_web_client_id will be configured incorrectly. It will be >pointing to the auto generated web client id of your new Firebase project; we >don't want this. In step 1 of https://developers.google.com/identity/sign-in/android/backend->auth, we call #requestIdToken(getString(R.string.server_client_id)). In >firebaseUI, this is also done and this resource is 'default_web_client_id' - >generated by google-services.json. This needs to be changed. So to resolve the issue you need to use the web OAuth client ID from project >#1, you can do this by either: Changing the google-services.json file - you'd need to change the client_id >fields to the correct web client id from project #1 You also need to whitelist (Auth > Sign In Providers > Google) the web client >OAuth from project#1 to project#2 Not use google-services.json so you can set the default_web_client_id himself. We made a guide for this, see here. Here's the process I followed to get this working: Go to GCP Console > Select old project > Apis and services > Credentials Create credentials > OAuth client ID Select Web application Enter a name Leave Javascript origins and authorized redirect URLS blank Copy the client id Open firebase console Go to authentication > sign-in method > google Whitelist the new client id > add > save Go back to settings > add firebase to your android app Add your android package name Leave signing certificate empty Click register app Download & open google-services.json In oauth_client there will be an entry for each oauth client id in your app (FYI these can be seen on the GCP console under Apis and services > Credentials). Delete the whole oauth_client tag and replace with "oauth_client": [ { "client_id": "<your_new_client_id>", "client_type": 3 } ], If you need any of the other oauth clients then make sure that the whitelisted one is at the top as this seems to be the default. Save the file & copy into your android app module. Make sure you have the following dependencies: project root build.gradle classpath 'com.google.gms:google-services:4.0.0' app module build.gradle compile 'com.google.firebase:firebase-core:16.0.0' compile 'com.firebaseui:firebase-ui-auth:4.0.0' Build & Run your project If you get this error (with no futher details): BasicNetwork.performRequest: Unexpected response code 400 for https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?alt=proto&key=AIzaSyBJL6EO8vMEJpyWUCAKP8ZgH4LYR0Hrwpk Check your gradle dependendies are set to the versions above (or higher) If you get this error: com.google.firebase.FirebaseException: An internal error has occurred. [ Invalid Idp Response:the Google id_token is not allowed to be used with this application. Its audience (OAuth 2.0 client ID) is <your-client-id>, which is not authorized to be used in the project with project_number: <your-project-number>. ] Try removing & re-adding your whitelisted client id on the firebase console.
Google sign in failed com.google.android.gms.common.api.ApiException: 10:
So I'm Stuck on this frustrating issue. I am quite new to Google Auth on Firebase but I done everything the firebase docs instructed in how to integrate the Google SignIn Auth, yet I'm still receiving this weird Error in the console consisted of two parts: 12-03 11:07:40.090 2574-3478/com.google.android.gms E/TokenRequestor: You have wrong OAuth2 related configurations, please check. Detailed error: UNREGISTERED_ON_API_CONSOLE and also Google sign in failed com.google.android.gms.common.api.ApiException: 10: Before Anyone attempts to point out similar questions that have previously been asked on stack overflow, Here's what I have done till now after seen all the available solutions and yet non has resolved the error I have my SHA1 fingerprint for my project I have my OAuth 2.0 client ID, both, the android client id and the web client and in the requestIdToken() I have put the web client id. I did not publish my project's APK on google play store. which means I did not accidentally generate another SHA1 fingerprint. I have followed step by step the Google Sign in Auth firebase docs. here is my code snippet: #Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_signup); ButterKnife.bind(this); String webClientId = getString(R.string.web_client_id); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .requestIdToken(webClientId) .build(); mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); mGoogleSignInClient = GoogleSignIn.getClient(this, gso); GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this); googleLoginBtn.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View view) { Intent signInIntent = mGoogleSignInClient.getSignInIntent(); startActivityForResult(signInIntent, RC_SIGN_IN); } }); } #Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { // The Task returned from this call is always completed, no need to attach // a listener. Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try{ GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { // Google Sign In failed, update UI appropriately Log.w(TAG, "Google sign in failed", e); // [START_EXCLUDE] Toast.makeText(this, "Gooogle Auth failed", Toast.LENGTH_LONG); // [END_EXCLUDE] } } } private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); // [START_EXCLUDE silent] //showProgressDialog(); // [END_EXCLUDE] AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { #Override public void onComplete(#NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information Log.d(TAG, "signInWithCredential:success"); FirebaseUser user = mAuth.getCurrentUser(); Toast.makeText(LoginActivity.this, "Successful Auth", Toast.LENGTH_LONG).show(); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCredential:failure", task.getException()); Toast.makeText(LoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); //updateUI(null); } // [START_EXCLUDE] //hideProgressDialog(); // [END_EXCLUDE] } }); }
Basically problem is in the SHA1 key put on console please regenerate it and put again properly same project. 1)As the answers, make sure that your actual signed Android apk has the same SHA1 fingerprint as what you specified in the console of your Firebase project's Android integration section (the page where you can download the google-services.json) For more info, see: Generate SHA-1 for Flutter app 2)On top of that go to the Settings of your firebase project (gear icon right to the Overview at the top-left area. Then switch to Account Linking tab. On that tab link the Google Play to your project. EDIT: Account Linking tab doesn't exist any more, instead : Sign in to Firebase. Click the Settings icon, then select Project settings. Click the Integrations tab. On the Google Play card, click Link.
When using App Signing by Google Play and Firebase, you need to add the SHA-1 fingerprint of the App signing certificate (found on Google Play Console/ Release Management/ App signing certificate) to the Firebase Console/ Settings/ SHA certificate fingerprints Updated location for the SHAs: Google Play Console > Release > Setup > App integrity
In My case, There is no problem with SHA-1 I have done GoogleAuth using Firebase. I forgot to add implementation 'com.firebaseui:firebase-ui-auth:4.3.1' And I put my own key instead of R.string.default_web_client_id, So that was the problem. I added above dependency and replace R.string.default_web_client_id with my own key. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.default_web_client_id)) .requestEmail() .build(); UPDATE : 18-Dec-2020 We can also use without requestIdToken like below. For this you must have to add your SHA1 to google console. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build();
I was facing the same issue, After checking around for a solution, from regenerating the finger print to linking the app on firebase to the Google play console and publishing the signed apk, the issue was actually because I was using the release SHA-1 on the firebase console. If you are still on debug mode, use the debug.keystore SHA1 Only use the release SHA1 if you are on production mode https://developer.android.com/studio/publish/app-signing.html
My solution was a little different, After hours of trying various things. I found my solution: Using the steps listed here: https://stackoverflow.com/a/34223470/10575896 Open Android Studio Open your Project Click on Gradle (From Right Side Panel, you will see Gradle Bar) Click on Refresh (Click on Refresh from Gradle Bar, you will see List Gradle scripts of your Project) Click on Your Project (Your Project Name form List (root)) Click on Tasks Click on Android Double Click on signingReport (You will get SHA1 and MD5 in Run Bar(Sometimes it will be in Gradle Console)) The console will print out the SHA keys for both debug and release. I had added the debug keys to firebase sometime in the past, but I had not added the release keys. I simply added the SHA1 and SHA256 keys to firebase, and I was good to go.
If you have all configuration valid in firebase like SHA-1 and you have imported right google-services.json file still you are getting error then add the support email in firebase console You have to add support email in fire base console Go to Project-> Setting -> General -> Public setting add Support Email
i was dealing with this problem for 2 days ! the problem was the clientId i used, was android type while i had to use web Aplication type Clientid . please consider this if you have the same problem ;)
I had problems with each answer, so here is the solution that worked for me: First, add Firebase to your project: Go to Firebase web site -> Add Project -> Once when you create new project go to Add App and add your Android app Take care to add the exact package name and debug SHA-1 key. You can generate debug SHA-1 key doing the following in Android Studio: On the right side open Gradle panel -> go to Tasks -> android -> run signingReport Your SHA-1 key will be shown in Run window Once when you register the app, download the config file. In the config .json file you can find your client_id : client -> oauth_client -> client_id Take care there are two client_ids. The one with "client_type": 3 worked for me with the following code: private fun requestSignIn(context: Context) { GoogleSignIn.getLastSignedInAccount(context)?.also { account -> onSignedIn(account) return } val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(Scope("https://www.googleapis.com/auth/spreadsheets")) .requestEmail() .requestIdToken("client_id_goes_here") .build() val client = GoogleSignIn.getClient(context, signInOptions) startActivityForResult(client.signInIntent, REQUEST_SIGN_IN) } Then in the onActivityResult: override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == REQUEST_SIGN_IN) { if( resultCode == RESULT_OK) { GoogleSignIn.getSignedInAccountFromIntent(data) .addOnSuccessListener { account -> onSignedIn(account) } .addOnFailureListener { e -> Log.d("Fail", "Fail") } } } } In onSignedIn you should do the google sheet api call
Make you use .requestIdToken(getString(R.string.default_web_client_id)) when you Build GoogleSignInOptions: GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.default_web_client_id)) .requestEmail() .build(); Add your debug.keystore's SHA1 and SHA256 fingerprint to your Firebase project with the following steps: Obtain the debug.keystore's fingerprints: Linux/Mac - keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore, Windows - keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore Add these fingerprint's to your Firebases project's Android app section: https://support.google.com/firebase/answer/9137403?hl=en
Yo guys, make sure that you have installed google play services in android studio SDK Manager. After I did it, rebuild unity project — all works fine.
It's 2022 and I spent 7 hours debugging this! I am not a native Android developer so I didn't know what's what until now. Here is how I made it to work. 1) Make sure you have different build numbers between dev and prod! There are 3 different builds/app in the world that you are playing with: The one in Google Play Store that you can install. It has a build number associated with it, both in the Play Store and in the App -> tap and hold -> info. The one in Android Studio build that has release build flavor The one in Android Studio build that has debug build flavor The debug one is the one you can attach the debugger (the bug icon!) and release is the one that you cannot. Whatever you do, make sure these are different or you will pull your hair why it works here and not there! Android: Tag > Build > Release > then immediately version bump I am coming from a background that we tag and version right before the release. (e.g. backend) Here, if you do so, it messes everything up! So you should tag, then release, then version bump immediately! Ideally, the Play store should be 1.1.7, the release one should be 1.1.8 (yes, one version ahead as it's the one you are going to publish), and the debug one should be 1.1.8-debug. If you don't do so, and they are the same, Android OS is going to cache the packages/APKs. So even if you go and install the app from Play Store, it might use an Android Studio version that it has in cache, with its own certificate! (That took me 4 hours of not knowing why installing the same app from Play Store on two phones, yielded different behaviors -- one was using the cached APK from Android Studio USB builds.) 2) You need at least 4 different Oauth Client ID Keys from GCP! At this point, you should be aware of the crazy system that you should create a "Web" OAuth Client ID for Android, and also a dummy Android one! See this. Yes, you need one "Web" key, and one "Android" key to have the GoogleSignIn work. You should use the "Web" one almost everywhere (except for doing server-side token validation, where you verify the audience/issuer of the JWT). Regardless, without the unused dummy "Android" one, it's not gonna work. However, the part that I didn't know was that you need 3 Android + 1 Web! When you create an Android OAuth Client ID, it asks for a SHA-1. And each of those 3 apps has its own certificates, a.k.a SHA-1s. How to get 3 SHA-1s? For 2 and 3 (release and debug of Android Studio) you can get them from gradle via this solution. For the Play Store one, you have to go to Play Console > App Integrity > App Signing and get the "App signing" certificate from there. (The upload one should match your release one most likely.) Now, go ahead and create these 3 Android Ouath Client Ids + 1 for Web and hopefully Google SignIn will work everywhere!
I am not sure if this is the cause, but we might need to use the Web Client ID in the Android App before publishing it, read the following article, https://android-developers.googleblog.com/2016/03/registering-oauth-clients-for-google.html
After adding the SHA1 and SHA256 app signing certificates it still didn't work. Once I added the SHA1 App upload certificate it worked :)
After adding the SHA1 and SHA256 app signing certificates it works.
I have faced the same error and I solved it by fixing the value of WEB_CLIENT_ID You can check the value at: Authentication -> Sign-in Method -> Provider (ex: Google) -> Web SDK Configuration -> Web Client ID
In my case to work on the emulator, I followed the steps https://stackoverflow.com/a/46767856/6800637, and in addition to putting in https://console.firebase.google.com projectName/ settings / general, my signature key sha1 and sha256 I also put the key sha1 from [debug.keystore] which is shown when you follow the steps mentioned above
This status code means that you are providing unknown server client id. So I was able to resolve this issue by changing the OAuth Client ID at Android client: googleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken("web application client id") .requestEmail() .build() In https://console.developers.google.com/apis/credentials in your project you might need to generate: OAuth client ID -> Web Application and use this web application client id in your Android app.
I had this problem recently when trying to use google sign in using Firebase. I could fix it by updating requestIdToken in GoogleSignInOptions to the one provided as client_id in google-services.json file.
These are all great answers, in case anyone else is trying to have multiple firebase projects for one app, i.e. development and production the trick is when you want to test production, you'll need to upload the APK to Google Play if you use Google Play to manage the signing of your app. I used the internal testing track, and then it started working. You cannot just install the APK on your device with your debug keys, because it does not match the production keys in Firebase. Another side note - as others have mentioned - for some reason you need to use the "web" OAuth client ID, NOT the Android OAuth client. This is a really confusing thing for Google to do.
Although, the tutorial and the configuration page suggests to get the package name from the manifest file, it seems it is checked against the "applicationId" in the "app/build.gradle" file. There are two places to set the package name I've found so far: app/src/main/AndroidManifest.xml app/build.gradle android.defaultConfig.applicationId In my case those two names were different. Earlier I had updated the package name in the first file but forgot to update in the build.gradle file.
If you are on flutter, take a look on where you initialized your GoogleSignIn, for me adding the clientId parameter worked on iOS but breaks android try that as well
If you are having multiple apps under same Project in Firebase, make sure you are in the correct (App)com.xxx.yyy, that matchup with your current project you are doing in Android Studio. Then change the sha1 in settings of Firebase under proper (App)com.xxx.yyy and download the Json accordingly past it at, In project level view apps->build->source.
This might come if you have not set the SHA-1/SHA-256 hashes for your project.
I double-checked everything on the firebase console, I have correctly added SHA keys also I was facing an error. After spending hours I found the error was due to not setting up OAuth Consent in Google Console. So if any once facing the same issue please check this step as well, that might be your help you out.
if above help from other universe can't prevent Google making you fired from your company, below may be help you: edit file "build.gradle" (:app) in android{}, add these if missing, change file path, storePassword, keyAlias, keyPassword signingConfigs { debug { storeFile file('E:\\keystore.jks') storePassword '123456' keyAlias 'key0' keyPassword '123456' } release { storeFile file('E:\\keystore.jks') storePassword '123456' keyAlias 'key0' keyPassword '123456' } } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } debug { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' signingConfig signingConfigs.debug } } Build/Clean Project Sync Now if still not working, run Debug app, magical will appear
I also faced this problem and search many time but didn't get over this. then I tried firebase authentication and this was worked. try following steps : go to firebase - go to console(upper right corner) - click on your built app card - then click on authentication and then authenticate your id. try it.
Google Play Services Sign-in INTERNAL ERROR
I have just started implementing Google Sign In API, this is my configuration: I added this to gradle: compile 'com.google.android.gms:play-services:10.2.6' This is my OnCreate: gso=new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN) .requestEmail() .build(); googleApiClient=new GoogleApiClient.Builder(this) .enableAutoManage(this,this) .addApi(Auth.GOOGLE_SIGN_IN_API,gso) .build(); This is how I invoke the sign-in process: Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient); startActivityForResult(signInIntent, GOOGLE_SIGNIN_ID); But it doesn't work and it says Google Play Services has stopped working, in the logs it says "INTERNAL ERROR" I have linked my app to a service, I have the OAUTH2 code, I don't know what I'm doing wrong and am pretty much desperate, thanks for your help.
Add configuration file with SHA-1 hash of your signing certificate. Configuration file to your project add google-services.json in app directory of your Android Studio project
GoogleApiClient error with addApi(Plus.API) & addScope(Plus.SCOPE_PLUS_LOGIN)
I have an error in: addapi(Plus.API); plus is showing error and i don't know why. I use the next code, given by Google, and the "Plus" doesn't exist. GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); super.onStart(); mGoogleApiClient.connect(); The problem persist and i don't know what i'm making bad. I configured the google-services.json file following the instruction by google. And i got the OAuth and the sha, for make the config file. And i don't find the answer to this.
I guess you have not added the Google Play Services library in your app. Add the following line in your app's build.gradle file compile 'com.google.android.gms:play-services-plus:8.3.0'