googleSignIn not loading in Native

Solar2d build 2022.3677

This seems like such a simple thing, but I am not very experienced building Native Android operations. I need to get my app signed into Google (they disallow the cut/paste I was using to get the oauth2 auth code).

I added the googleSignIn but am getting the error
module ‘plugin.googleSignIn’ not found:resource (plugin.googleSignIn.lu) does not exist in archive

Build.settings:

        ["plugin.googleSignIn"] =
        {
            publisherId="tech.scotth",
            marketplaceId = "... my marketplace account ID"
        }

Then
googleSignIn = require(“plugin.googleSignIn”)

blows up.

The Solar2d simulator at least recognizes it and when I do the googleSignIn.init() says not available on this platform, which is correct.

Do I need to do something special like get the .so file? How do I tell AndroidStudio know where to find it?

I found the answer in an old post, thank you Vlad!

That did not fix the problem. I will keep playing with it, but still the same result.

I am kind of lost here. I tried the manual approach, copying the .jar file into the libs directory, but now I get duplicate reference:

Type plugin.library.BuildConfig is defined multiple times: /Users/Shared/Mobile/SlikRoad/android/plugin/build/.transforms/74af00c200714dd75c20180828b37193/transformed/classes/classes.dex, /Users/Shared/Mobile/SlikRoad/android/app/build/intermediates/external_file_lib_dex_archives/debug/0_jetified-plugin.googleSignIn.jar:classes.dex

Not sure what to try.

I am not sure the exact sequence, but now it works – with the .jar file manually copied into android/app/libs. I restarted several times, and then I did a clean and rebuild without the .jar file, then run debug with the .jar file.

Anyway, seems to work now.

Still not working. It builds and runs, but apparently the AndroidManifest.xml is confused. Running the gradle script removed my own app Native parts. I can get either my own CoronaApplication to start or the get googleSignIn CoronaApplication to work, but not both. How do I merge this so that they both work?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
          package="com.phosphorlearn.SilkRoad"
          android:installLocation="auto">

    <permission android:name="com.phosphorlearn.SilkRoad.permission.C2D_MESSAGE" android:protectionLevel="signature" />
	

    <uses-permission android:name="android.permission.INTERNET" />
	<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
	<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
	<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
	

    <uses-feature android:glEsVersion="0x00020000" />
	<uses-feature android:name="android.hardware.telephony" android:required="false" />
	<uses-feature android:name="android.hardware.screen.portrait" android:required="true" />
	<uses-feature android:name="android.hardware.screen.landscape" android:required="false" />
	

    

    <!-- Add android:name="CoronaApplication" to reactivate Application Delegate in Native Builds-->
    <application android:label="Corona App"
        android:name="CoronaApplication"
        tools:replace="android:name"
        >

    <!--application android:icon="@mipmap/ic_launcher"
                 android:banner="@drawable/banner"
                 android:label="@string/app_name"
                 android:largeHeap="true"
        android:label="Corona App"
        android:name="CoronaApplication"
        tools:replace="android:name"

                 android:networkSecurityConfig="@xml/network_security_config"
                 tools:replace="android:icon"
                 -->

        <meta-data android:name="targetedAppStore" android:value="google" />

        

        

        <!-- The main Corona activity that runs the Corona project. -->
        <activity android:name="com.ansca.corona.CoronaActivity"
    [...]

The result depends on timing, but usually this result from googleSignIn.init(…):
[Correction: init() appears to work fine, but the googleSignIn.signIn(googleSIListener) fails)

E/AndroidRuntime: FATAL EXCEPTION: GLThread 331
    Process: com.phosphorlearn.SilkRoad, PID: 8329
    java.lang.NullPointerException: null
        at com.naef.jnlua.LuaState.lua_pushstring(Native Method)
        at com.naef.jnlua.LuaState.pushString(LuaState.java:691)
        at plugin.googleSignIn.LuaLoader$MyHandler$1.executeUsing(LuaLoader.java:210)
        at com.ansca.corona.CoronaRuntimeTaskDispatcher$TaskEvent.Send(CoronaRuntimeTaskDispatcher.java:179)
        at com.ansca.corona.events.EventManager.sendEvents(EventManager.java:100)
        at com.ansca.corona.Controller.updateRuntimeState(Controller.java:325)
        at com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:434)
        at com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1625)
        at com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1380)

In case it helps, here is the lua call:

		googleSignIn.init({
			android={
			    clientId = GAPICID,
			    scopes= {"https://www.googleapis.com/auth/fitness.activity.read https://www.googleapis.com/auth/userinfo.email"}
			}
		})
		googleSignIn.signIn(googleSIListener)

Odd will take a look

1 Like

If you want to look at my source, I can share it (1 GB). It is messy because I have been trying several things.

Refinement: when the app is already signed in (omitting my CoronaApplication, signIn works), it crashes at the .signIn. With both included, when I force a signOut [mGoogleSignInClient.signOut();] then call your signIn, I first get a prompt to choose the account and then the stack dump.

More data: if I use silentSignIn(listener), I get no error but it never returns to the listener.

A little more data. I put print statements to see where it is going. It seems to be crashing at the end. I even removed the listener, and that didn’t help. Some kind of interaction with my CoronaApplication is corrupting the stack?

Source:

	print("in googleLogin")
	if googleSignIn then
		local gsistat = googleSignIn.init({
			android={
			    clientID = GAPICIDD,
			    scopes= {"https://www.googleapis.com/auth/fitness.activity.read https://www.googleapis.com/auth/userinfo.email"}
			}
		})
		print("GSI init returned: "..str(gsistat))
		local gsisi = googleSignIn.signIn(googleSIListener)
		print("GSI login returned: "..str(gsisi))
	else
		print("no googleSignIn")
	end

Result:

I/Corona: in googleLogin
I/Corona: GSI init returned: nil
I/Corona: GSI login returned: nil
D/: PlayerBase::stop() from IPlayer
D/AudioTrack: stop() called with 190519 frames delivered
D/EGL_emulation: eglMakeCurrent: 0xe3985ea0: ver 3 0 (tinfo 0xd035e6f0)
D/EGL_emulation: eglMakeCurrent: 0xe3985ea0: ver 3 0 (tinfo 0xd035e6f0)
D/EGL_emulation: eglMakeCurrent: 0xe3985ea0: ver 3 0 (tinfo 0xd035e6f0)
D/EGL_emulation: eglMakeCurrent: 0xe3985ea0: ver 3 0 (tinfo 0xd035e6f0)
E/libOpenSLES: frameworks/wilhelm/src/itf/IBufferQueue.cpp:56: pthread_mutex_lock_timeout_np returned 110
D/: PlayerBase::stop() from IPlayer
D/AudioTrack: stop() called with 4410 frames delivered
D/: PlayerBase::stop() from IPlayer
D/AudioTrack: stop() called with 1764 frames delivered
D/: PlayerBase::stop() from IPlayer
D/AudioTrack: stop() called with 882 frames delivered
E/AndroidRuntime: FATAL EXCEPTION: GLThread 324
    Process: com.phosphorlearn.SilkRoad, PID: 7105
    java.lang.NullPointerException: null
        at com.naef.jnlua.LuaState.lua_pushstring(Native Method)
        at com.naef.jnlua.LuaState.pushString(LuaState.java:691)
        at plugin.googleSignIn.LuaLoader$MyHandler$1.executeUsing(LuaLoader.java:210)
        at com.ansca.corona.CoronaRuntimeTaskDispatcher$TaskEvent.Send(CoronaRuntimeTaskDispatcher.java:179)
        at com.ansca.corona.events.EventManager.sendEvents(EventManager.java:100)
        at com.ansca.corona.Controller.updateRuntimeState(Controller.java:325)
        at com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:434)
        at com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1625)
        at com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1380)
I/Process: Sending signal. PID: 7105 SIG: 9
Disconnected from the target VM, address: 'localhost:64624', transport: 'socket'

I don’t know if it will help, but I took a screen movie of the AndroidStudio emulator and debug trace from app install through crash. It is at:

here

I built the app without Native, just from the simulator. The login works fine, although it returns ‘canceled’ to the listener (with isError=false). I’ll try to take a video of the sequence to show all the steps, see if I am doing something wrong. I thought it might be the clientID but I tried all the production/debug/web clientIDs and same result.

I put the video https://www.ideategames.org/googlesignin_canceled.mov

I can redesign my app to work without Native if I can get this to work, but I need the serverAuthCode returned by login.

I just looked at your error, there is a good chance you are using the legacy plugin(i.e not the one from the marketplace)

Try using this in build.settings

plugins = {
	 	["plugin.googleSignIn"] = {
        publisherId = "tech.scotth",
				supportedPlatforms= {
						android={url="https://solar2dmarketplace.com/marketplacePlugins?ID=MyAccountID&plugin=GoogleSignIn_tech-scotth&type=android"}
				}
  		}
	}

and then run “setUpCoronaAppAndPlugins” again

I did that (in simulator build, not in Native, I have given up on native for now), now it returns error 4.

[the rest of this is a red herring – I was using silentSignIn]

It does not show any signin screens. I checked my marketplace ID to be sure. I will try a few more things to be sure I am doing it right. I get no error in the simulator when it loads the plugin, only when it correctly says not available when I use it.

I have tried the various clientID I have without effect.

This forum post:

https://stackoverflow.com/questions/37739557/google-sign-in-error-4#:~:text=The%20error%20means%20that%20there,the%20app%20and%20reopened%20it.

says error 4 is

CodeHasNoAuthInKeychain

Is that something I am doing wrong? Here is my code:

		googleSignIn.init({
			android={
			    clientId = GAPICID,
			    serverClientId = GAPICIDW,
			    scopes= {"https://www.googleapis.com/auth/fitness.activity.read https://www.googleapis.com/auth/userinfo.email"}
			}
		})

Indicates there are no valid auth tokens in the keychain. This error code will be returned by restorePreviousSignIn if the user has not signed in before or if they have since signed out.

Are you getting this error calling googleSignIn.signIn(listener)?

Oops, return code 4 was a red herring.
[I was using silentSignIn – I am embarrassed to say that I had tried that and forgot to reset it. ]

But still not working, getting “canceled” and blank data.

So blank data I thought might mean wrong clientID. I’ll try all of them. Stay tuned…

I get status canceled and blank data for all the clientId or serverClientId I try.

I think I might have misunderstood the directions. It appears I have to include Firebase in my application in order to get google-services.json.

I have used Firebase in the past, so I already have a google-services.json. I just didn’t understand that was required by googleSignin.

Result with google-services.json, the build-settings including that, the clientId copied from google-services.json is the same, “canceled”. I am out of ideas.

A little extra data point: after login and confirmation from 2-factor, sometimes there is a flash of the “choose Google account” window (probably always there but sometimes too quick to see). I assume this is shown first then overwritten by the login screen. That might indicate the problem, where the cancel is coming from?

I have been solving this problem for a few days, and now it is solved successfully.

  1. Your ClientID should use Web instead of Android!.
    (In a nutshell, please set the same value that I circled in my picture)

  2. After that, you will get the login information, but it is impossible to log in to Firebase. I suggest you purchase Mr.Scott’s Firebase Auth after trying it out.

firebaseAuth.signInWithGoogle(Google_IDToken, Google_AccessToken,function (ev)
	if(ev.isError) then
		native.showAlert( "Error", ev.error ,{"Ok"} )
	else
		native.showAlert( "Yes", json.encode(ev) ,{"Ok"} )
	end
end)
1 Like

I tried using the web client ID, both in clientId = … and with serverClientId = …

Always the same result: status=“canceled” and blank data, no matter which clientID I use – web, android, android debug (using debug SHA1), or the one in the google-services.json file.

FYI, I do not need Firebase, I only need the oauth authorization code, event.serverAuthCode returned from login. I used to get it with a webview but Google no longer allows that. Then I used a browser asking the user to cut/paste the auth code, but Google no longer allows that starting September.

All I need is a Google sign in with return of event.serverAuthCode.

Also FYI, I am not using Native any more, just simple googleSignIn with Solar2d build.

Today I am getting a warning I have not seen before:

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

This alert shows up on require().

The link then takes me to the GoogleSignIn page in the Solar2d marketplace, with the status ‘Activated’.

My build.settings has:

            publisherId="tech.scotth",
            -- marketplaceId = "<MID>",
            supportedPlatforms= {
                android={url="https://solar2dmarketplace.com/marketplacePlugins?ID=<MID>&plugin=GoogleSignIn_tech-scotth&type=android"}
            }

It doesn’t matter if I use marketplaceId = or supportedPlatforms = , result is the warning of an outdated plugin.

How do I get an updated version?

@dmarques42
My build setting only has the following, it can be used normally.

["plugin.googleSignIn"] =
{
	publisherId="tech.scotth",
	marketplaceId = "XXXXXXXX",
},

@Scott_Harrison
Regards, Google says:『 We are discontinuing the Google Sign-In JavaScript Platform Library for web. The library will be unavailable for download after the March 31, 2023 deprecation date. Instead, use the new Google Identity Services for Web.
By default, newly created Client IDs are now blocked from using the older Platform Library, existing Client IDs are unaffected. New Client IDs created before July 29th, 2022 can set plugin_name to enable use of the Google Platform Library.』
Will this have any effect on the existing plugins “GoogleSignIn and FirebaseAuth”?

@dmarques42 You should use the settings @vb66r55 attached above (remove the supportedPlatfroms). Can you dm your Solar2D Sim project?

@vb66r55 the googleSignIn/Firebase Auth plugins use the newest native apis/sdk from Google. They don’t use JS/Web sdks so will have no affect

1 Like