Google Play Game Services

Monkey Forums/User Modules/Google Play Game Services

Ironstorm(Posted 2014) [#1]
Hi folks!

I want to share my latest module for MonkeyX.

Google Play Game Services... for Android.

Currently it supports Achievements and Leaderboards with native UI. Turn-based Multiplayer will coming soon.

GitHub Repo: https://github.com/Ironstorm/bbd
Documentation: see module folder /documentation/start.html

Maybe I will port the subclasses of achievements and leaderboards. To get the ability to gather information about them and display those in the own app. But for now, the native UI should be good enough.
iOS and Windows Phone support isn't planned yet. Maybe I will port it, when there is enough demand.

Warning: This is still WIP. Please test it before you release your game!


erebel55(Posted 2014) [#2]
Thank you Ironstorm! :D


therevills(Posted 2014) [#3]
Congrats!

Wow lots of resources!!! Do you need all of them?

The monkey/native code looks pretty clean, I think I would have extracted the helper classes out of the Google example though.


MikeHart(Posted 2014) [#4]
Thanks man, that is awesome. Did you use that in PairsX?


Ironstorm(Posted 2014) [#5]
Wow lots of resources!!! Do you need all of them?

Yeah, Android supports a lot of different languages. I don't know, what happens when you put those away.


The monkey/native code looks pretty clean, I think I would have extracted the helper classes out of the Google example though.

After I've managed to get this working for the first time, I was afraid to change the code in such a big way ... so maybe for the next release :D


Did you use that in PairsX?

Currently not. I wanted to implement it with my own UI. For that, I've to port the subclasses for achievements and leaderboards. But maybe I will upload a native UI version to Google Play.
And after that, I want to integrate turn-based Multiplayer into PairsX.


therevills(Posted 2014) [#6]
I was afraid to change the code in such a big way ...

LOL... I'm the same!

I'll have a look thru the code and see if we can make it a bit smaller and a bit more dynamic (i.e. let the user input the IDs in Monkey code instead of the resource file).

In your help html you have a call to UpdateAsyncEvents... just wondering why?


Ironstorm(Posted 2014) [#7]
I'll have a look thru the code and see if we can make it a bit smaller and a bit more dynamic (i.e. let the user input the IDs in Monkey code instead of the resource file).

This one was my biggest point on the wishlist, but haven't found a solution without to create a new target instead of a module.

I've wrote mark an email days ago and asked for a new feature in trans which allows to copy resource files to the build dir, like "#LIBS" and "#SRCS" works. But haven't got an answer, maybe he's busy right now :)

In your help html you have a call to UpdateAsyncEvents... just wondering why?

Oh yeah, this is deprecated. It will be a part of the next update in which you can retrieve some asynchronous datas. (Turn-based multiplayer, Login-Response-Codes and such). Will remove it from the example later.


Ironstorm(Posted 2014) [#8]
Sorry for double post. But I wanted to share my app update of PairsX. I've integrated Play Game Services with this module.
Currently there are missing graphics for the achievements, will add those tomorrow when I'm at the office.

Just download the free version here: https://play.google.com/store/apps/details?id=com.blackbirddesign.pairsxfree

Once you've signed in, there will be two additional buttons on the bottom left corner. Just press those to access the achievements and the leaderboard.

Oh, and please. Just comment here about the Play Game Service and the module. I will create a project thread for PairsX tomorrow.


Kslam(Posted 2014) [#9]
@Ironstorm Hope that u can create Windows Phone 8 leaderboard binding soon.


Snader(Posted 2014) [#10]
Awesome work Ironstorm! Many thanks!


Ironstorm(Posted 2014) [#11]
Hope that u can create Windows Phone 8 leaderboard binding soon.

Sorry, there's no Windows Phone support for Google Play Game Services, at least not yet.


Snader(Posted 2014) [#12]
I am trying to get this into Spaceshippy! but somehow as soon as I add it I get these errors, which to me, doesn't have anything to do with the gameplayservices.

-compile:
[javac] Compiling 3 source files to D:\Programming\Projects\Spaceshippy\spaceshippy.buildv78c\android\bin\classes
[javac] D:\Programming\Projects\Spaceshippy\spaceshippy.buildv78c\android\src\com\voornmutimedia\spaceshippy\MonkeyGame.java:4067: error: cannot find symbol
[javac] req.addTestDevice( test_dev );
[javac] ^
[javac] symbol: method addTestDevice(String)
[javac] location: variable req of type AdRequest
[javac] D:\Programming\Projects\Spaceshippy\spaceshippy.buildv78c\android\src\com\voornmutimedia\spaceshippy\MonkeyGame.java:4112: error: AdRequest() has private access in AdRequest
[javac] AdRequest req=new AdRequest();
[javac] ^
[javac] D:\Programming\Projects\Spaceshippy\spaceshippy.buildv78c\android\src\com\voornmutimedia\spaceshippy\MonkeyGame.java:4162: error: AdRequest() has private access in AdRequest
[javac] AdRequest adRequest = new AdRequest();
[javac] ^
[javac] Note: D:\Programming\Projects\Spaceshippy\spaceshippy.buildv78c\android\src\com\voornmutimedia\spaceshippy\MonkeyGame.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 3 errors

BUILD FAILED
d:\android-sdk\tools\ant\build.xml:720: The following error occurred while executing this line:
d:\android-sdk\tools\ant\build.xml:734: Compile failed; see the compiler error output for details.

Total time: 4 secondsTRANS FAILED: Android build failed.

Abnormal program termination. Exit code: -1


Ironstorm(Posted 2014) [#13]
Gnarrr ... The Admob classes are now contained within Google play Services. So if you attempt to add the Admob-6.4.1 lib to your project you will get dex error because of duplicate classes...

I will have to port the Admob part of Google Play Game Services to get both running.
Maybe I can help you out with an update in a couple of hours.


Ironstorm(Posted 2014) [#14]
Uploaded a new update of GameServices. Now I've added Admob in the same way as the BRL module does.

Just download the update, and replace your Admob import line with the following:

Import bbd.gameservicesadmob ' replace Import brl.admob with this one


Done some quick testing. Worked here. Please, be aware. This only works if you integrate the GameService as well.


Why0Why(Posted 2014) [#15]
Great addition to Monkey. Thanks for doing it!


Snader(Posted 2014) [#16]
It is working fine now after I replaced the admob from brl with the new one from you and got rid of the admobInterstitial module from therevills.

The rest is really simple to implement, thanks again.


Snader(Posted 2014) [#17]
Alright, it all works fine. But when I now submit my apk to Google Play, it starts moaning about the version number, which should be higher than 1.4.1. So I made a version 2.

#ANDROID_VERSION_CODE="2"
#ANDROID_VERSION_NAME="2.0"

After building and running on my phone, the AndroidManifest.xml in the bin directory shows correctly:

android:versionCode="2"
android:versionName="2.0"

The appinfo on my phone shows correctly 2.0.

New since your module is this part, which somehow seems to be causing the problems:

<meta-data android:name="com.google.android.gms.appstate.APP_ID" android:value="@string/app_id" />;<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id" />;<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />;<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

Should the ; be in there? Is it possible that the google checkscripts somehow miss the correct versionnumber because of this?

UPDATE:

To find out what's happening, I reverted everything. Back to 'old admob' and versionnr on 1.4.2. APK was build correctly and I was able to submit it to Google Play.

So the module seems to work fine, but I am not able to publish the apk anymore.

(btw.. To support you, I bought your game on Android. The kids love it.)


erebel55(Posted 2014) [#18]
So, we currently can't use this along side admobinterstitial?


Ironstorm(Posted 2014) [#19]
Should the ; be in there? Is it possible that the google checkscripts somehow miss the correct versionnumber because of this?

This is placed by trans. I've looked into the trans code, but couldn't find anything. To be honest, I don't know where those semicolons comes from. I will look into it. But there shouldn't be a problem with those ones.

Hm, Google recjected your app? I haven't had any problem with PairsX at all. Maybe I'm missing something. Will check it out.

So, we currently can't use this along side admobinterstitial?

Currently not, will add this feature within the next update.


Ironstorm(Posted 2014) [#20]
Uploaded a new update. Now Admob and Interstitial Ads should work. I've copied therevills code and added the new methods and requirements. So it should work the same.

@Snader:
I've looked into your problem. Couldn't find a solution. You're sure, that Google is moaning about the version number? Because if you upload an apk with an incorrect version number, you get an error like this:
"You need to use a different version code for your APK because you already have one with version code 20."

You need to set only the android:versionCode higher than the previous version. Google does not use android:versionName for any internal purpose, other than to enable applications to display it to users.


Snader(Posted 2014) [#21]
Google rejected my akp -update- because the version nr is lower than the version already online. Although the AndroidManifest says 2.0, and the phone appinfo says 2.0, google still rejects it because of a version nr that is lower.

One moment, you where posting the same time as I did.. Results of another test:

Current version at Google Play:
VERSION
141 (1.41)
7 mrt. 2014

New monkey version:
#ANDROID_VERSION_CODE="2"
#ANDROID_VERSION_NAME="2.0"

After build, signing and stuff at Google play:
- Upload mislukt
- De versiecode van uw APK moet hoger zijn dan 141.

Which is in English something like: Upload failed, version should be higher than 141


Ironstorm(Posted 2014) [#22]
Try to set #ANDROID_VERSION_CODE="142" and if you want #ANDROID_VERSION_NAME="1.4.2" or #ANDROID_VERSION_NAME="2.0"
As you wish.


Snader(Posted 2014) [#23]
When I do this, it works:

New monkey version:
#ANDROID_VERSION_CODE="200"
#ANDROID_VERSION_NAME="200"

Always thought that the dots had some meaning..

Thanks for the Interstitial Ads! Awesome!


Snader(Posted 2014) [#24]
With the latest version the Admob ad shows:

"missing adactivity with android configchanges in androidmanifest.xml"

UPDATE: Solved it by adding this just before </application> in the androidmanifest.xml:

<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>


Ironstorm(Posted 2014) [#25]
Damn ... sorry, my fault.
Updated the GitHub Repo.

I've accidentally removed a AndroidManifest line from the gameservicesadmob.monkey file ... sorry for that.


erebel55(Posted 2014) [#26]
Thank you for the great documentation :) I plan on giving this a try within the next couple days. Would love to see if you could make it smaller as well.


Supertino(Posted 2014) [#27]
Woot! Google Play Services Woot! Woot! OMG! Woot! YES! Sweet!

@ Ironstorm I hereby give you permissions to marry my sister.


Ironstorm(Posted 2014) [#28]
Would love to see if you could make it smaller as well.

I don't think, there's a way to make the lib smaller. I can look through the resources, maybe some of them aren't necessary.

I hereby give you permissions to marry my sister.

Hm, sounds tempting, but I've to reject the offer. My better half wouldn't be happy.

At the moment, I'm on the multiplayer part. Switched from turn-based to realtime multiplayer. It works, but currently the module doesn't handle errors like disconnect or failures. This is the next step towards a new update. Maybe this weekend.


arawkins(Posted 2014) [#29]
Awesome! Thanks Ironstorm! Looking forward to trying this out.


erebel55(Posted 2014) [#30]
Can you update the "Step 3" in your start.html documentation?


Step 3: Copy resources

To run the module, you need to configure the application ID as a resource. Also, you have to prepare your Android target and copy various resource-files to your build dir.
1.Go to the module folder - bbd/native/
2.Copy the bbd/native/res folder to your Android build dir. There should be an res folder already. Overwrite existing files.
3.Open res/values/ids.xml and replace the placeholder application ID in the app_id resource.

Now you're almost done.



I copied the bbd/resources/res folder into my build/android/ directory

And copied the entire bbd folder to MonkeyXPro78c/modules/

However, when I try to run your example given in Step 5 it throws "The Google Play services resources were not found. Check your project configuration to ensure that the resources are included. Google Play Store is missing"


Lugato(Posted 2014) [#31]
Hi Ironstorm,

I tried build a little app test with your module and when I test it with my Xperia Z1, the app don't open, my android version is 4.3.

I tried download pairsX game, but google give me a message inform me that the app isn't compatible with my device.

Can you give me some help ?


Ironstorm(Posted 2014) [#32]
However, when I try to run your example given in Step 5 it throws "The Google Play services resources were not found. Check your project configuration to ensure that the resources are included. Google Play Store is missing"

Did you try to run it on a real device or the emulator? Seems to me, you've tried it on the emulator. You can only test it on a real device.

I tried build a little app test with your module and when I test it with my Xperia Z1, the app don't open, my android version is 4.3.

Hm, strange. Could you test if you've installed the Play Services? You can download it here: https://play.google.com/store/apps/details?id=com.google.android.gms


Ironstorm(Posted 2014) [#33]
I tried download pairsX game, but google give me a message inform me that the app isn't compatible with my device.

You should try to download the new version (maybe it'll take a few hours to go online). Added missing xxhdpi-screen resources. Now Nexus 5 and Xperia Z1/Z2 should be supported too.

The new update of the BBD-Gameservices-module will require more time than I had thought. :/ Couldn't find a good solution to handle those huge amount of callbacks. But I'm on it!


erebel55(Posted 2014) [#34]
@Ironstorm, yep you were right; it works on a device. Thank you! :)


erebel55(Posted 2014) [#35]
I am having an odd issue with bbd.gameservicesadmob vs brl.admob.

When using brl.admob, banner ads appear 3 to 4 seconds after calling ShowAdView.
When using bbd.gameservicesadmob, banner ads take 60 seconds to appear after calling ShowAdView.

Example below, I have replaced the digits in my ad id with x characters.

brl.admob example:


bbd.gameservicesadmob example:



Ironstorm(Posted 2014) [#36]
Yep, fixed this one. This is a known GMS Admob issue. Had to set a background color for the Adview (in my case COLOR.TRANSPARENT). Without it, the initial ad won't show up.

GitRepo updated.


Snader(Posted 2014) [#37]
Thanks for the update Ironstorm. This makes hell of a difference!


erebel55(Posted 2014) [#38]
Thank you for the quick response Ironstorm; that fixed the issue :)


bruZard(Posted 2014) [#39]
However, when I try to run your example given in Step 5 it throws "The Google Play services resources were not found. Check your project configuration to ensure that the resources are included. Google Play Store is missing"

I've the same issue on my Devices (no emulator).


caffeinekid(Posted 2014) [#40]
I managed to add this to Thrusty Tubes with no issues. Thanks for a great module. :)


Ironstorm(Posted 2014) [#41]
I've the same issue on my Devices (no emulator).

Sorry for the late reply. Wasn't able to answer yet.
Have you copied all resources from the res folder? Are they in the build dir after building?

If both yes, which device are you testing?


bruZard(Posted 2014) [#42]
Yes and yes.

My Devices:
Sony Xperia Z
Samsung Galaxy S4
Samsung Galaxy Tab 2 10.1
Motorola Milestone 2


Ironstorm(Posted 2014) [#43]
Hm, okay. Four devices and none of it works? Strange ...
But the Play Store is on every one of those devices? Can you check, if the Google Play Services is out of date? Just go to https://play.google.com/store/apps/details?id=com.google.android.gms

Maybe I missing something. I've tested it on a Galaxy S4, and it worked fine. Which MonkeyX version are you using? And all of them are running the original Android? No custom roms or something like that.


bruZard(Posted 2014) [#44]
i've no idea which kind of magic is happen ... but now, it works


erebel55(Posted 2014) [#45]
Ironstorm, can you post an example of doing this?

After users sign in successfully for the first time in your game, your game should sign them in automatically whenever they start the game again, until they explicitly sign out.
You have to save the sign-in state by yourself. For example with "SaveState" and "LoadState".


Thank you


MikeHart(Posted 2014) [#46]
Hi Ironstorm,

no that Mark won't come up with an official module, I put my hopes on you :-) If you need help, let me know.


erebel55(Posted 2014) [#47]
Ironstorm, hoping you could post an example soon if you get on. Thanks!


Ironstorm(Posted 2014) [#48]
Ironstorm, hoping you could post an example soon if you get on. Thanks!

Sorry ... some stressful days :/

Here's a little demo, which one should show how to use the SaveState() and LoadState routine. Of course, in this example it's a lot easier than in a complete game where you have to save different user settings/highscores in the SaveString function.

Import bbd.gameservices
Import mojo

Function Main()
	New MyApp
End

Class MyApp Extends App
	Field gameservice:GameService
	Field state:String
	
	Method OnCreate()
		gameservice = New GameService						' Create GameService
		
		state = LoadState()									' Load the app state
		
		If state = "1" Then gameservice.beginUserSignIn()	' If state is one, the user should be logged in automatically
		
		SetUpdateRate(60)
	End
	
	Method OnUpdate()
		
			If TouchHit() Then
				If gameservice.isLoggedIn() = False Then
					gameservice.beginUserSignIn()			' Log user into Game Services
					state = "1"								' Save the login state
				Else
					gameservice.signOut()					' Logout
					state = ""
				EndIf
			EndIf
		
	End
	
	Method OnSuspend()
		SaveState(state)
	End
	
	Method OnResume()
		state = LoadState()
	End
	
	Method OnRender()
		Cls()
		
		If gameservice.isLoggedIn() Then
			DrawText("Logged in!", 10, 10)
		Else
			DrawText("Tap on the screen to login to game services", 10, 10)
		EndIf
	End
	
End



erebel55(Posted 2014) [#49]
Thank you! :)


erebel55(Posted 2014) [#50]
For some reason the sign in page is getting shown in my game if the user suspends and resumes. I am writing up a quick sample of what my code looks like and will post here when I'm finished.


erebel55(Posted 2014) [#51]
Ironstorm, turns out the behavior is present in your examples as well.

So, I added some print statements to try and figure out where it is logging in at, however it doesn't hit either of the Print "Signing In..." statements I added. So I am pretty puzzled on why it would be signing the user in. Please see example below.



To reproduce the issue
1) Run my example / or any of your own
2) Suspend the app (before touching the screen to signin)
3) Resume the app and it will sign you in without having to touch the screen

I took a look in the native code and I didn't see any onSuspend or onResume stuff so I am pretty stumped.
Hope you can take a look :)


Ironstorm(Posted 2014) [#52]
Will look into it in a couple of hours. Sry, it's currently 2:15 AM here in Germany. Hope you can wait.


erebel55(Posted 2014) [#53]
Sure thing, thanks Ironstorm!


therevills(Posted 2014) [#54]
Sure thing, thanks Ironstorm!

Your too soft Ethan, you should be cracking the whip and tell him he needs to fix it ASAP - LOL! ;)


erebel55(Posted 2014) [#55]
Let me know if you can reproduce the issue ;)


Ironstorm(Posted 2014) [#56]
Let me know if you can reproduce the issue ;)


I've seen your previously posted image ;D
I'm still on it, could reproduce the issue, but haven't found a solution yet.

Your too soft Ethan, you should be cracking the whip and tell him he needs to fix it ASAP - LOL! ;)

Lol Steve, give him the carrot and stick ... :P


erebel55(Posted 2014) [#57]
Haha okay cool, you are the best Ironstorm :)


Ironstorm(Posted 2014) [#58]
Finally I've solved the issue. Had to set "mHelper.setMaxAutoSignInAttempts(0);" ... so simple -.-
Also I've added isNetworkAvailable() to check if an internet connection is available.

https://github.com/Ironstorm/bbd


erebel55(Posted 2014) [#59]
Yay, looks good :) Thank you Ironstorm!

However, now if I login and stop the game and then start it again I get a NPE on my beginUserSignIn() call within OnCreate.

See example,




erebel55(Posted 2014) [#60]
Actually I think the NPE was my fault (unless you can reproduce it).

However, now if I click to sign in and then cancel (instead of signing in) it will never let me try to sign in again.
So, after a cancel beginUserSignIn() doesn't do anything now.


therevills(Posted 2014) [#61]
Been playing around with this and the new Android target, committed my version to Diddy using the Google Play jar which comes with MonkeyX:

http://code.google.com/p/diddy/source/detail?r=f9e302e998c9b81d2f5d76080d8df302f2301355

You still need to copy ids.xml... I tried hard coding the Id into the meta-data manifest line but Android refused to use it :(

Also added ShowAllLeaderBoards if your game has multiple leaderboards.


therevills(Posted 2014) [#62]
Found an issue when you instantiate the game service object and straight after try to log in will cause a null pointer exception, due to the threading the game service isn't full ready yet.

Seems better to create the object in OnCreate and sign in in OnUpdate to give game service a chance to full kick in.


programmer(Posted 2014) [#63]
@Ironstorm,
Does Google Play Services require Maps API key?
https://github.com/Ironstorm/bbd/blob/master/gameservices.monkey#L24