Google play services integration

Hi all,
I’ve been using for a while extension-googleplaygames lib from @fbricker for using google play games services, and just wanted to try google-play-services lib from @player_03.

I could add the haxelib to my project.xml and i could compile without any problem.

But i don’t know how to integrate this java library with my haxe code, any simple example would be nice.

For example where is the java code which i am supposed to link via JNI.

The library provides no Haxe bindings. All it does is make Google’s classes available to your Java code. You’ll have to write your own Java code (which you may be able to copy-paste from Google’s documentation) and your own JNI bindings.

If you only need features provided by extension-googleplaygames, you may want to use that for convenience. Actually, the two libraries appear to be compatible, meaning that you can use extension-googleplaygames to import and manage Google’s game services, and then use google-play-services to import anything else you happen to need. This way, you’ll only need to write Java code for the non-games services.

I am trying to make those bindings but where should i write my java code?

My problem is that looking @fbricker code I can see he has both inside the extension,
the java code and the haxe code.
But if the extension doesn’t have Haxe bindings, where do i write those?

Inside your library, creating a new extension or in my own project folder?

Edit: I have decided to create a new extension and I could bind my haxe methods with my plain android methods, but now, how do i use your library @player_03 I mean I suppose I have to write a dependency with your library, but in which file.

I imagine it is in the new Extension include.xml file, but is it right?

Creating an extension is the cleanest solution, though you could also use templates if you just need one or two Java files.

Your Haxe bindings can go anywhere. At runtime, you’ll be able to access any Java code from any Haxe file (if you know the Java code’s fully-qualified class name). From an organizational standpoint, it makes sense to store it near the Java code, as in the extension examples you’ve seen.

include.xml is correct, and the xml code remains exactly the same.

I don’t know what I am doing wrong but I can’t compile my gpgConnection Extension:

My include.xml file looks like:

<extension>
	<dependency name="gpgconnection" path="dependencies/android" if="android" />
	<android extension="org.haxe.extension.GpgConnection" />

	<haxelib name="google-play-services" if="android" />
	<dependency name="google-play-services" path="google-play-services" if="android" />
	<set name="google-play-game-services" />
</extension>

And I have tried as well with:

<project>
	<dependency name="gpgconnection" path="dependencies/android" if="android" />
	<android extension="org.haxe.extension.GpgConnection" />

	<haxelib name="google-play-services" if="android" />
	<dependency name="google-play-services" path="google-play-services" if="android" />
	<set name="google-play-game-services" />
</project>

In my java file I am just trying to use this as an example:

...
import com.google.android.gms.games.Games;
...
private Games games;

But I get:

C:\Users\trabajo\Documents\Trabajo\haxe\Pruebas\GooglePlayGamesConnection\Export\android\bin\deps\gpgconnection\src\main\java\org\haxe\extension\GpgConnection.java:13: error: package com.google.android.gms.games does not exist
import com.google.android.gms.games.Games;
                                   ^
C:\Users\trabajo\Documents\Trabajo\haxe\Pruebas\GooglePlayGamesConnection\Export\android\bin\deps\gpgconnection\src\main\java\org\haxe\extension\GpgConnection.java:47: error: cannot find symbol
	private Games games;

Edit: I just have copied most of your gradle.build file and it is working now, but i am wondering what I am missing with my include.xml because it is not working if I leave it as I showed you.

Sorry for the late response, but I figured it out. Your <haxelib /> tag included my library, which automatically included the correct dependency. Then your <dependency /> tag created a second dependency with the same name, causing Lime to forget about the first. This meant the build.gradle file was never copied into the Android project, and so it failed until you manually copied it.

There might also be an error somewhere in your build output, saying that your main project doesn’t have a subfolder named “google-play-services.”

1 Like