gameNetwork.show("achievements") does nothing on Android ?

Hi @evanspro,

Keep me posted on your tests. Step back and make sure you’re getting the correct plugin initialized, and are getting at least basic response from the service. Then move on to implementing features.

Brent

I’ve been using this guide : https://coronalabs.com/blog/2013/06/25/tutorial-introducing-google-play-game-services/

A few things have changed since, but it’s seems to be up to date.

The GPGS has been set accordingly to the guide. Once my achievement have been added, I published them, after linking them to this app.

I’ve made a new app, with 3 buttons : a first one that connects to GPGS, a second one that unlocks an achievement and a third one, that simply shows the achievements list. Here is the code :

build.settings

settings = { plugins = { ["CoronaProvider.gameNetwork.google"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true }, }, }, orientation = { default = "landscapeRight", supported = { "landscapeLeft", "landscapeRight"}, }, android = { googlePlayGamesAppId = "XXXXXXXXXXXXX", versionCode = "1", versionName = "0.5", usesPermissions = { "android.permission.INTERNET", "android.permission.VIBRATE" }, }, }

main.lua

-------------------------------------------------------------------------------------------- -- Variables -------------------------------------------------------------------------------------------- local \_W = display.contentWidth \* 0.5; local \_H = display.contentHeight \* 0.5; local gameNetwork = require("gameNetwork") local initCallback local requestCallback -------------------------------------------------------------------------------------------- -- Initialization Callback -------------------------------------------------------------------------------------------- function initCallback(event) -- Android if not event.isError then --native.showAlert("Success!", "", { "OK" }) print("gameNetwork : connected") else --native.showAlert("Failed!", event.errorMessage, { "OK" }) print("Error Code:", event.errorCode) end end -------------------------------------------------------------------------------------------- -- Request Callback -------------------------------------------------------------------------------------------- function requestCallback(event) if (event.type == "unlockAchievement") then -- High score has been set print("event.type == unlockAchievement") end end -------------------------------------------------------------------------------------------- -- BUTTONS -------------------------------------------------------------------------------------------- local buttonListener local button01 local button02 local button03 button01 = display.newImage("button01.png") button01.x = \_W button01.y = \_H - 100 button01.action = "connect" button02 = display.newImage("button02.png") button02.x = \_W button02.y = \_H button02.action = "unlock" button03 = display.newImage("button03.png") button03.x = \_W button03.y = \_H + 100 button03.action = "show" function buttonListener(event) if event.phase == "ended" or event.phase == "cancelled" then -- Connecting to gameNetwork if event.target.action == "connect" then gameNetwork.init("google", initCallback) -- Unlocking achievement XXXXXXXXXXXXXXXXXX elseif event.target.action == "unlock" then gameNetwork.request("unlockAchievement", { achievement = { identifier = "XXXXXXXXXXXXXXXXXX" }, listener = requestCallback } ) -- Showing achievements elseif event.target.action == "show" then gameNetwork.show("achievements") end end end -- Adding touch events button01:addEventListener("touch", buttonListener) button02:addEventListener("touch", buttonListener) button03:addEventListener("touch", buttonListener)

And that’s it. I still have the same issue : button01 seems to successfully initializes gameNetwork(), while button02 and button03 do absolutely nothing. I don’t even have any output message.

At this point, my guess is that I’ve probably made a mistake while configuring GPGS, but honestly, I can’t be sure : I’m really not used to work with GPGS and I don’t know what to look or where to look.

I’ve tried installing the app on my tabled with an App Installer (“ES Explorateur”), and with Google Play (by setting the app as an alpha test). And I’ve tried to build my app with a debug keystore and also with a release keystore… Nothing changed.

And, just in case, I’m using Corona v2015.2772.

… Mhhh, I’ve just made a quick test ! 

In my build.settings file, I’ve changed the googlePlayGamesAppId and  replaced it with something else (“2”) :

 android = { googlePlayGamesAppId = "2", versionCode = "1", versionName = "0.5", usesPermissions = { "android.permission.INTERNET", "android.permission.VIBRATE" }, },

This doesn’t seem to change anything, meaning that in the console, I’ve got this (which is exactly the same as before) :

V/Corona (10378): \> Class.forName: CoronaProvider.gameNetwork.google.LuaLoader V/Corona (10378): \< Class.forName: CoronaProvider.gameNetwork.google.LuaLoader V/Corona (10378): Loading via reflection: CoronaProvider.gameNetwork.google.LuaLoader I/Corona (10378): gameNetwork : connected

Would that mean that my initCallback() doesn’t really work ?

Hi @evanspro,

Can you add some more print() debugging to check what may or may not be happening? In cases like these, I often do a pairs() dump on the “event” to see what’s actually inside it:

[lua]

for k,v in pairs( event ) do

   print( k,v )

end

[/lua]

And then I add that as the very first line inside the callback function , before any other conditional blocks begin.

Let me know what your results are. It sounds like you’re getting GPGS initialized, which is a first positive step. Beyond that it may just be configuration of achievements and so forth inside the Google system.

Brent

Hi Brent !

I’ve added your print function in the initCallback() function and in the requestCallback() function and some other print() function.

-------------------------------------------------------------------------------------------- -- Variables -------------------------------------------------------------------------------------------- local \_W = display.contentWidth \* 0.5; local \_H = display.contentHeight \* 0.5; local gameNetwork = require("gameNetwork") local initCallback local requestCallback -------------------------------------------------------------------------------------------- -- Initialization Callback -------------------------------------------------------------------------------------------- function initCallback(event) print("initCallBack()") for k,v in pairs( event ) do print( k,v ) end -- Android if not event.isError then --native.showAlert("Success!", "", { "OK" }) print("gameNetwork : connected") else --native.showAlert("Failed!", event.errorMessage, { "OK" }) print("Error Code:", event.errorCode) end end -------------------------------------------------------------------------------------------- -- Request Callback -------------------------------------------------------------------------------------------- function requestCallback(event) print("requestCallback()") for k,v in pairs( event ) do print( k,v ) end if (event.type == "unlockAchievement") then -- High score has been set print("event.type == unlockAchievement") end end -------------------------------------------------------------------------------------------- -- BUTTONS -------------------------------------------------------------------------------------------- local buttonListener local button01 local button02 local button03 button01 = display.newImage("button01.png") button01.x = \_W button01.y = \_H - 100 button01.action = "connect" button02 = display.newImage("button02.png") button02.x = \_W button02.y = \_H button02.action = "unlock" button03 = display.newImage("button03.png") button03.x = \_W button03.y = \_H + 100 button03.action = "show" function buttonListener(event) if event.phase == "ended" or event.phase == "cancelled" then -- Connecting to gameNetwork if event.target.action == "connect" then print("button action == \"connect\"") gameNetwork.init("google", initCallback) -- Unlocking achievement #1 elseif event.target.action == "unlock" then print("button action == \"unlock\"") gameNetwork.request("unlockAchievement", { achievement = { identifier = "XXXXXXXXXXXXX" }, listener = requestCallback } ) -- Showing achievements elseif event.target.action == "show" then print("button action == \"show\"") gameNetwork.show("achievements") end end end -- Adding touch events button01:addEventListener("touch", buttonListener) button02:addEventListener("touch", buttonListener) button03:addEventListener("touch", buttonListener)

This is what I get right after touching the “gameNetwork.init()” button :

I/Corona (25025): initCallBack() I/Corona (25025): type init I/Corona (25025): name init I/Corona (25025): data true I/Corona (25025): gameNetwork : connected

Then, once I call gameNetwork.request(“unlockAchievement”), or gameNetwork.show(“achievements”), nothing happens.

So, gameNetwork.request(“unlockAchievement”) and gameNetwork.show(“achievements”) don’t respond. The callback for “unlockAchievement” isn’t even called. 

I guess I misconfigured GPGS but I really don’t know where to look :confused:

So you don’t even get the “print(“requestCallback()”)” line to execute? As in, it’s not even reaching the callback function?

How are you testing, and on which devices?

No, it stops right at :

I/Corona (26787): button action == "unlock"

I’m testing the app on my Nexus Tablet , Android 5. I’ve tried two things : installing my app (alpha version) from the Google Store, but also by simply transferring the APK with an app installer (“ES Explorateur”)

EDIT : And also, I’ve checked, all the Google Play Game Management,Google Play Game Services,Google+ APIs are enabled. The Google Play Games app is also installed. And I can see my game in the Google Play Games app.

I assume you built the app using “Google Play” as the target store? And when you do builds for updating it, does everything match between Corona’s build window and Google, i.e. Application name, Version code, Version name, Package, the same keystore, etc.?

Brent

I think so… I’ve rebuilt my app to check and everything seems to be good compared to Google. The gameNetwork.request(“unlockAchievement”) is still stuck at the same point.

I assume you’ve gone through all of this already?

http://developer.android.com/google/play-services/games.html

Yes ! I guess I’m gonna have to redo it again, just to be sure. It’s quite probable I’ve made some mistakes at this point.

If by any chance you have other ideas about what I should check, don’t hesitate.

I’ll keep you posted ! Thanks for your help and your patience :slight_smile:

The positive thing is that it seems to be at least communicating with Google, thus the response from init(). So now it’s potentially a matter of dissecting the Google console side and making sure your achievements are all properly set up, etc.

Brent

So far, still no luck ! I’ve redone the whole process again, and gameNetwork.request(“unlockAchievements”) still doesn’t respond.

I’ve followed each steps as detailed on the Corona Blog (even though it’s probably a little bit outdated) and on the Game Developers Documentation

Here’s what I’ve done :

  • I’ve recreated a new app on Google Play developer Console
  • I uploaded a new APK as an Alpha Test version, using a new package name (this part doesn’t seem to be necessary at this point but since Google does directly ask to upload an APK file…)
  • I created a new Game Service, declaring that I wasn’t using a Google API.
  • I linked it to the previously created Android app (the one previously created), using the same package name (disabled anti-piracy).
  • I authorized the app.
  • I retrieved the client ID
  • Added the client ID in my Corona project
  • Rebuilt the APK
  • Uploaded it again as an alpha version
  • Added it on my tablet.

But a few things went differently than expected. As detailed in the b.2 section, it says I should have had this screen :consoleCreateClientIdDialog1.png

Which should have been followed by this one : 

consoleAndroid2.png

Instead, I had a small window simply showing the Signing certificate fingerprint (SHA1), which does look like to the last field shown in the previous screenshot. I didn’t have to select “Application type” or “Installed application type”, and I hadn’t to retype the package name again.

This is probably because Google has changed their process in order to simplify things, but I’m really not sure.

I created the client and received my Client ID. Again, the window wasn’t the same as the one shown in the Google Developer Documentation. It showed the “full” client ID and the client ID I’m supposed to add in my game.

Hi again !

So, I’ve remade some tests. In the build.settings file, I’ve changed the _ googlePlayGamesId _ value to a random string (my first and second name to be sure it would’nt something that already exists ). Once I build the app and test it, here’s what shows up in the console after calling gameNetwork.init(“google”, initCallBack) :

I/Corona (20107): type init I/Corona (20107): name init I/Corona (20107): data true I/Corona (20107): ### GameNetwork CONNECTED!

So, I do have some data return by my callback, and it looks like it’s connected… but it shouldn’t, right ? Is it normal ?

And of course, nothing happens when I’m calling gameNetwork.request().

Finally !!! :slight_smile:

That’s it, I’ve found my issue. The problem wasn’t an issue in the Google console side ! The problem was actually quite simple and it was a really stupid mistake from me !

The quick answer was : “I’m was not properly initiating the Google Play Game Service” !

This is what I was using to initiate the GPGS :

function initCallback(event) print("initCallBack()") for k,v in pairs( event ) do print( k,v ) end -- Android if not event.isError then --native.showAlert("Success!", "", { "OK" }) print("gameNetwork : connected") else --native.showAlert("Failed!", event.errorMessage, { "OK" }) print("Error Code:", event.errorCode) end end gameNetwork.init("google", initCallback)

This does return some data in the console, but something was actually missing ! As mentioned in the Corona blog :

Once the proper service is initiated, we use gameNetwork.request() again to log in the player locally. Assuming this is successful, the loadLocalPlayerCallback() function is called. The event table of this function contains a data table which in turn contains information such as the player “alias” (event.data.alias) or the player’s network ID (event.data.playerID). At this stage, it may be useful to save this player data locally to a text/JSON file or a SQLite database.

That’s it, this is the part I was forgetting (I honestly don’t know how I’ve even been able to skip that part since I’ve redone this guide at least 4 times !)

So my final, working, code should have been :

function gpgsInitCallback( event ) gameNetwork.request( "login", { userInitiated=true, listener=gameNetworkLoginCallback } ) end function initCallback(event) print("initCallBack()") for k,v in pairs( event ) do print( k,v ) end -- Android if not event.isError then --native.showAlert("Success!", "", { "OK" }) print("gameNetwork : connected") gameNetwork.init( "google", gpgsInitCallback ) else --native.showAlert("Failed!", event.errorMessage, { "OK" }) print("Error Code:", event.errorCode) end end gameNetwork.init("google", initCallback)

I’ve been able to figure this out by testing an other Android game made with Corona SDK (“You Will Crash”) . I’m really not used to the Android OS so I didn’t know how it used to work and I saw that, right after initiating the GPSP, there was an Android loader showing up, that I hadn’t in my app.

I feel really bad for “forcing” you to  try to understand what didn’t work, but you still helped me a lot !

So thanks a lot, hope no one makes the same mistake :slight_smile: