googleSignIn not loading in Native

I have been using both, to the same effect. But using exactly as @vb66r551 wrote, with my MID, I get

You are using on unsupported plugin, please see updated plugin on solar2dmarketplace.com

in the simulator and ‘canceled’ with a build on the device. I don’t know what ‘dm your project’ means, but I can zip it up for you to try. There must be some simple setting or coding flaw I have.

Now the warning message has disappeared. I assume it was something with the marketplace.

The build still has the same result on a device, status = “canceled”
Here is all the relevant code:

local function googleSIListener(event)
	-- event.status== "signed in", "cancelled", "error". 
	if event.isError then 
		print("GSI error is: "..event.error)
		IG.alertBig("event returned from login",json.encode(event))
		print("status: "..str(event.status))
	elseif event.status == "not signed in" then
		print("not signed in, so try to sign in")
		M.googleLogin()
	else
		GSIuser = {
			email = event.email,
			uid = event.userId,
			idtoken = event.idToken,
			photoUrl = event.photoUrl,
			displayName = event.displayName,
			givenName = event.givenName,
			familyName = event.familyName,
			accessToken = event.accessToken,
			serverAuthCode = event.serverAuthCode,
			scopes = event.scopes,
		}
		print("received data: "..json.encode(GSIuser))
		local msg = event.status=="signed in" and json.encode(GSIuser) or "status: "..str(event.status).."\n\ndata: "..json.encode(event)
		IG.alertBig("data returned from login",msg)
		print("status: "..str(event.status))
		if GSIuser.serverAuthCode then
			if string.len(str(GSIuser.serverAuthCode)) > 5 then
				GAPICODE = IG.trim(GSIuser.serverAuthCode)
				getToken()
			end
		elseif not triedTwice then
			timer.performWithDelay(5000, function() googleSignIn.getCurrentUser(googleSIListener) end)
			triedTwice = true
		end
	end
	BB.isGoogleLogin = false

end

local haveDoneGInit
function M.googleSignInInit()
	print("initializing googleSignIn")
	if googleSignIn and not haveDoneGInit then
		local initrtn = googleSignIn.init({
			android={
			    clientId = GAPICIDF,
			    -- serverClientId = GAPICIDW,
			    -- scopes= {"https://www.googleapis.com/auth/fitness.activity.read https://www.googleapis.com/auth/userinfo.email"}
			    scopes= {"https://www.googleapis.com/auth/userinfo.email"}
			}
		})
		-- always returns nil
		print("init return: "..str(initrtn))
		haveDoneGInit = true
	else
		print("no googleSignIn or already done: "..str(haveDoneGInit))
	end
end

function M.googleLogin()
	BB.isGoogleLogin = true
	-- local googleSignIn = require("plugin.googleSignIn")
	print("in googleLogin")
	if googleSignIn then
		googleSignIn.signIn(googleSIListener)
	else
		print("no googleSignIn")
	end
end

Anything else I should try? I can try a bare bones project and gradually build up my current one, though that will be a big job. But all I can think of to try. I am wiling to share the full code if that helps.

You need to use your own marketplaceId in the build.settings, here is a demo with working clientId’s (don’t use in production). The project worked on a few different computers. 9/10 times some on has had a problem with this project it has alway been with getting the client ids. Google does not make easy in my opinion. I have done my best to explain what do in my docs.

googleSignIn-demo.zip (324.6 KB)

OK, I have been using my marketplace ID, and have tried all the clientID I have. I’ll start with your example and try to build from there.

Here is what I find confusing in your documentation. It is in the Setup paragraph.

Also you need google service enabled in your build.settings (see below) and you need a google-services.json file( if you are using firebase you can skip this step). Go to this link, follow the steps, and put the file(google-services.json) in the root of your project.

That is before the Firebase Setup, yet (as your link shows) google-services.json only comes from Firebase. And yet I used the Google API clientID, not one of those in the google-services.json file? In your example posted above, you do not use google-services.json.

That is what I find confusing. Yet, no combination works for me, I must have the project set up wrong in Google.

Same result with your app using my credentials. Loading the plugin is not the problem, it loads and runs fine.

I created a new clientID with a new keystore, several different devices, and always the same result. Must be something wrong with my project on Google.

You have to set google-services.json.

Then set your Client-ID to the same value as the red circle in this picture.

If it still doesn’t work, I suggest you use “Twitter Login”, it will be much easier.

I tried using google-services (which is for Firebase, not for plain Google projects) before Scott said not to use that. Doesn’t make any difference. I don’t know that Twitter login will give me what I need, an auth key for getting fitness data.

Very frustrating. I tried creating a new Google project, very simple access, new app name, registered the SHA1, the clientId gives the same ‘canceled’ result.

Anyone else can try and I think get the same result:

  1. create a simple sign-in app (using Scott’s simple code example above)
  2. Build with package name com.phosphorlearn.SilkRoad2
  3. Build with debug keystore and alias androiddebugkey (default, should have SHA1 00:85:F2:62:A2:91:F0:D1:CE:9E:E9:FB:CD:1D:50:E7:82:6D:BE:9D)
  4. use clientId = “709195245465-il66disbt6go4et9ohcbg7uleukcue87.apps.googleusercontent.com

I created that Google API project just for this testing. Can use any login account.

I cannot afford the Google support that is now required, so I logged it as a bug with Google. Probably won’t help.

All I can think of is that my Google account is corrupted. I have created several projects, many different package/SHA1 combinations, all with the same result.

Can someone create a simple Google project with any package name and SHA1=00:85:F2:62:A2:91:F0:D1:CE:9E:E9:FB:CD:1D:50:E7:82:6D:BE:9D (that is for debug.keystore androiddebugkey alias) for me to try? Then I could prove to Google that it is my account – or, if it doesn’t work, I know it is my coding. I don’t see how that is, I am using exactly what Scott gave me except for my package name and clientId.

Another data point: I used a completely different app Firebase clientID and package name (with google-services.json), still the same result.

My code (tiny modification from @Scott_Harrison ) is at googleSignIn-DM.zip

Build with package org.ideategames.Samarkand and debug.keystore/androiddebugkey

googleSignIn-DM.zip (373.0 KB)

I am curious when you build with my client id and project if you had success

I would need the package name and the keystore to use.

Using com.coronalabs.googleSignIn or com.coronalabs.googleSignIn_demo and the debug.keystore, does not return to the listener and does not give any error. Using that package name with any client id gives the same no-return result. But disconnect does give an error (forgot first 2 lines, added later):

08-28 15:56:33.636  5370  5407 I Corona  : ERROR: Runtime error
08-28 15:56:33.636  5370  5407 I Corona  : ?:0: attempt to call field 'disconnect' (a nil value)
08-28 08:44:32.695 29967 29986 I Corona  : stack traceback:
08-28 08:44:32.695 29967 29986 I Corona  : 	?: in function '_onEvent'
08-28 08:44:32.695 29967 29986 I Corona  : 	?: in function '?'
08-28 08:44:32.695 29967 29986 I Corona  : 	?: in function '?'
08-28 08:44:32.695 29967 29986 I Corona  : 	?: in function <?:189>

I didn’t think to guess for the package name, I guess that is not registered.

I am using your project almost exactly as you sent it, only my package name and my client id – or various versions of those.

This feels like a red herring, but behavior today is weird. As above, when I use package name com.coronalabs.googleSignIn, or com.coronalabs.googleSignIn_demo I get no return to the listener.

But when I use my package org.ideategames.Samarkand or any of my package names, all other code identical, I get a crash with no stack dump. But when I restart the app, I get this stack dump crash:

08-28 10:21:13.614 11687 11703 I Corona  : ERROR: Runtime error
08-28 10:21:13.614 11687 11703 I Corona  : java.lang.NullPointerException: null
08-28 10:21:13.614 11687 11703 I Corona  : Java Stack Trace:
08-28 10:21:13.614 11687 11703 I Corona  : 	com.naef.jnlua.LuaState.lua_pushstring(Native Method)
08-28 10:21:13.614 11687 11703 I Corona  : 	com.naef.jnlua.LuaState.pushString(LuaState.java:691)
08-28 10:21:13.614 11687 11703 I Corona  : 	plugin.googleSignIn.LuaLoader$silentSignIn.invoke(LuaLoader.java:406)
08-28 10:21:13.614 11687 11703 I Corona  : 	com.ansca.corona.JavaToNativeShim.nativeRender(Native Method)
08-28 10:21:13.614 11687 11703 I Corona  : 	com.ansca.corona.JavaToNativeShim.render(JavaToNativeShim.java:205)
08-28 10:21:13.614 11687 11703 I Corona  : 	com.ansca.corona.Controller.updateRuntimeState(Controller.java:364)
08-28 10:21:13.614 11687 11703 I Corona  : 	com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:434)
08-28 10:21:13.614 11687 11703 I Corona  : 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1625)
08-28 10:21:13.614 11687 11703 I Corona  : 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1380)
08-28 10:21:13.614 11687 11703 I Corona  : stack traceback:
08-28 10:21:13.614 11687 11703 I Corona  : 	[C]: in function 'silentSignIn'
08-28 10:21:13.614 11687 11703 I Corona  : 	?: in main chunk
08-28 10:21:13.614 11687 11703 I Corona  : ERROR: Runtime error
08-28 10:21:13.615 11687 11703 I Corona  : java.lang.NullPointerException: null
08-28 10:21:13.615 11687 11703 I Corona  : Java Stack Trace:
08-28 10:21:13.615 11687 11703 I Corona  : 	com.naef.jnlua.LuaState.lua_pushstring(Native Method)
08-28 10:21:13.615 11687 11703 I Corona  : 	com.naef.jnlua.LuaState.pushString(LuaState.java:691)
08-28 10:21:13.615 11687 11703 I Corona  : 	plugin.googleSignIn.LuaLoader$silentSignIn.invoke(LuaLoader.java:406)
08-28 10:21:13.615 11687 11703 I Corona  : 	com.ansca.corona.JavaToNativeShim.nativeRender(Native Method)
08-28 10:21:13.615 11687 11703 I Corona  : 	com.ansca.corona.JavaToNativeShim.render(JavaToNativeShim.java:205)
08-28 10:21:13.615 11687 11703 I Corona  : 	com.ansca.corona.Controller.updateRuntimeState(Controller.java:364)
08-28 10:21:13.615 11687 11703 I Corona  : 	com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:434)
08-28 10:21:13.615 11687 11703 I Corona  : 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1625)
08-28 10:21:13.615 11687 11703 I Corona  : 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1380)
08-28 10:21:13.615 11687 11703 I Corona  : stack traceback:
08-28 10:21:13.615 11687 11703 I Corona  : 	[C]: ?
08-28 10:21:13.615 11687 11703 I Corona  : 	[C]: in function 'silentSignIn'
08-28 10:21:13.615 11687 11703 I Corona  : 	?: in main chunk

More on this ‘disconnect’ error. This is for any non-existence package name. I get nothing back on signIn, but on Sign Out, if I comment this out:

function signOut_onEvent(event)
	if(event.phase == "ended")then
        -- googleSignIn.disconnect(googleListener)
        googleSignIn.signOut(googleListener)
	end
end

Then I get a return on Sign Out.

Refined data:

If the package name is something nonexistent (com.coronalabs.googleSignIn, com.phosphorlearn.googleSignIn, org.ideategames.googleSignIn), the Sign In just doesn’t return, but no crash.

If the package name is an existing one of my registered package names (org.ideategames.Samarkand, com.phosphorlearn.SilkRoad), the app crashes on Sign In.

Obviously something returned from Google on a valid package/clientId combination – exactly the return I want – is causing the plugin to crash. Yesterday, just returned ‘canceled’, today crashes.

This is all with the original code above from @Scott_Harrison , modified only with different clientId.

If someone could supply me with a working package name and client id with the debug build, I could maybe see what is wrong with my setup.

I assume you know, but yesterday and today this message again:

I just build with package id “com.coronalabs.googleSignIn_demo” for my demo project. I have used the project a two of my computers I don’t think it my clientID depends on a keystore

As for your warning, I am assuming you already put in your own marketplaceId in your build.settings. The attached demo does “not” have a marketplaceId inside. Also please make sure the plugin is active https://solar2dmarketplace.com/plugins?GoogleSignIn_tech-scotth )
If you still see that warning I would clear out your cache, in your finder go to

“/Users/YourComputerUserNameHere” (aka the home folder) and delete the “Solar2DPlugins” folder

Lastly go to “/Users/YourComputerUserNameHere/Library/Application\ Support/Corona/Simulator” delete the “Plugins” folder.

If you are getting the popup still, likely your marketplaceId is wrong or does not have the Google Sign In plugin active

Without changing anything, not clearing cache, this afternoon the popup is gone.

My marketplace ID is in build.settings.

But using your client id with com.coronalabs.googleSignIn_demo, built with debug.keystore, results in “canceled”, just as before. I also get this for every combination of my own client ID and package.

I think the keystore matters. You have to put in the SHA1 of the keystore to get a clientID. And you need to create different client IDs for debug and production. At least that is how I understand the Google documentation.

I don’t know what I am doing wrong. The only things different between your project and mine, as far as I can tell, are 1) keystore (?), 2) the account I use for login.

And of course the device, but I am trying different devices, all with the same result.

I just noticed in your screenshot using the doc page to make a client id, https://developers.google.com/identity/sign-in/android/start. That does not make consent screen is likely cause “cancel error”
I would strong recommend not doing it this way in following the steps in the documentation. I changed the doc wording around to hopefully make it clearer.

Go to google console, create new project or open an existing project, go to credentials(Under APIs & Services), create a new credential, select OAuth client ID, make one for Android/iOS, on Applcation type “Android” make sure to add SHA-1(learn more here) and Package Name (see example below), on iOS click your created client id under OAuth 2.0 client IDs, you want to use this client id on iOS (see example below),and put “iOS URL scheme” into build.settings(see below). Also you need google service enabled in your build.settings (see below) and you need a google-services.json file( if you are using not using firebase you can skip this step). Go to this link, follow the steps, and put the file(google-services.json) in the root of your project(again this is only needed if use Firebase).

Sorry, I am confused by this. I followed the Google documentation, you are recommending not doing it that way?

And here is what I find still confusing in your documentation – it is the same steps as the Google documentation.

Go to google console, create new project or open an existing project, go to credentials(Under APIs & Services), create a new credential, select OAuth client ID, make one for Android/iOS, on Applcation type “Android” make sure to add SHA-1(learn more here) and Package Name (see example below),

That is exactly what I did to get the screenshot above, and you said to not do it that way. I am not understanding something, it seems to me you are saying to not do it that way, then in the documentation saying to do it that way. What am I misunderstanding?

The above screen was made from:

  1. Google console
  2. new project
  3. credentials, new OAuth client
  4. Android
  5. package name org.ideategames.Samarkand
  6. SHA-1

What is the error? Can you show me what the credentials page should look like that is different?

One thing I understand that you say – the consent screen. It is true that I never see the consent screen (the one that specifically allow the scopes I requested). That seems to be what is not happening. What do I do differently to get that? I have filled out the Oauth Consent Screen page also, my project is in testing mode so it should work for my test users.