Tutorial on how to setup extensions with HaxeFlixel for mobile - Admob - Analytics - Google play games

  • It was hard for me to be able to make these extensions work together with Haxeflixel 4.3.0 so I’ll write this post in case anyone encounters the same problems.

    These are useful tools for android and ios games. I only tested it on android but this also should work on ios.

    We are going to implement these libraries:


    Google Analyytics:

    Google play game services (Achievements and leaderboards)

    Admob is an extension to monetize using ads, Analytics is used to measure things about users and Google play games to display achievements and scoreboards.
    Haxelib libraries:
    This is the list of all the libraries once installed. You can look your list doing:

    Haxelib list

    extension-admob: [1.6.4]
    extension-android-support-v4: [1.0.0]
    extension-googleplaygames: [1.5.7]
    extension-googleplayservices-basement: [1.1.0]
    flixel-addons: [2.5.0]
    flixel: [4.3.0]
    ganalytics-git: [git]
    google-play-services: [1.1.0]
    haxelib_client: [3.2.0-rc.3]
    hxcpp: [3.4.64]
    openfl: [3.6.1] 

    There seems to be a problem if you are using the library hscript for Haxeflixel and compiling the release version. If you have that library, remove it:

    haxelib remove hscript

    Setup Android:

    First, If you didn’t do it you need to setup Lime to be able to build apps for android. To do it you need to write:

    Lime setup android

    Follow the instructions to install the SDK and JAVA but download the NDK separately from: https://developer.android.com/ndk/downloads/index.html

    I’m using r16b. This is needed to recompile the analytics extensions later.

    Tell lime where you installed ndk with Lime setup android.

    When you finished installing the sdk go to the folder where is at and open the sdk manager. Upgrade the android sdk tools and platform tools to 25.2.5 and 27.0.1 respectively.

    Then install sdk platform for api 23 and google repository from extras.

    We need to recompile hxcpp with the new NDK. To do that execute:

    openfl rebuild hxcpp android -clean

    For more details on Android Development this is a good tutorial: http://www.steverichey.com/dev/openfl-android-tips-and-tricks/

    Setup Extensions:

    For admob and Google play install the extensions from Haxelib. I’m using the following versions:

    Admob 1.6.4
    Google-play-services 1.1.0

    For analytics we need to download the git versión 1.0.0 using haxelib:

    haxelib git ganalytics-git https://github.com/emibap/GAnalytics.git

    This extension needs to be recompiled using the ndk we downloaded on the previous step. To build it just execute build.bat from the library folder. It will create a folder called ndll.

    All these extensions also need extension-googleplayservices-basement to configure the dependencies from the android sdk. The main problem I had was that the tool included on this extension to download new dependencies didn’t worked for me and the only thing that it did was to delete all dependencies. So I needed to install them by hand.

    All dependencies installed need to be from the same version to work. So we are going to need to update all dependencies. To do it go to the folder where you installed the sdk and search for the gms. It is on:

    ...Android SDK\extras\google\m2repository\com\google\android\gms

    Here you have folders for every dependency. Inside you have them by versión number. I’m using version 11.0.4

    Inside the version folder you have a .aar file that can be decompressed using WinRar or a similar program.

    You need to put the content from the .aar files on the folder dependencies from extension-googleplayservices-basement. The structure for each folder is:

    • libs ( here you put classes.jar from the .aar)
    • res (Copy it from the .aar )
    • src (Copy it from the .aar )
    • AndroidManifest.xml (Copy it from the .aar. We need to configure these later)
    • build.xml (Copy it from the template folder)
    • project.properties (Copy from the template folder)

    Do these process for each dependency you need installed. The dependencies I installed are:


    After that you need to check if the manifests are fine. Check the manifest for every dependency, if it defines an sdk dependency delete it and on the project.xml for your project add:

    <android target-sdk-version="23" if="android" />

    The manifest for google-play-services-analytics-impl need to be edited to add a few services needed for the extension:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.gms.analytics">
        <!-- Include required permissions for Analytics to run. -->
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        <!-- Optional permission for Analytics to run. -->
        <uses-permission android:name="android.permission.WAKE_LOCK"/>
    	<!-- Optionally, register AnalyticsReceiver and AnalyticsService to support background
    	  dispatching on non-Google Play devices -->
    	 <receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
    			 <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
    	 <service android:name="com.google.android.gms.analytics.AnalyticsService"
    	 <!-- Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable
    	  installation campaign reporting -->
    	 <receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
    			 <action android:name="com.android.vending.INSTALL_REFERRER" />
    	 <service android:name="com.google.android.gms.analytics.CampaignTrackingService" />

    Then you need to edit the include.xml from extension-googleplayservices-basement to add the new dependencies. Here is how my file looks:

    <?xml version="1.0" encoding="utf-8"?>
    	<section if="android">
    		<dependency name="google-play-services-basement"
    			if="google-play-services-basement" />
    		<dependency name="google-play-services-ads-lite"
    			if="google-play-services-ads-lite" />
    		<dependency name="google-play-services-auth"
    			if="google-play-services-auth" />
    		<dependency name="google-play-services-base"
    			if="google-play-services-base" />
    		<dependency name="google-play-services-drive"
    			if="google-play-services-drive" />
    		<dependency name="google-play-services-plus"
    			if="google-play-services-plus" />
    		<dependency name="google-play-services-games"
    			if="google-play-services-games" />
    		<dependency name="google-play-services-gcm"
    			if="google-play-services-gcm" />
    		<dependency name="google-play-services-analytics"
    			if="google-play-services-analytics" />
    		<dependency name="google-play-services-analytics-impl"
    			if="google-play-services-analytics-impl" />
    		<dependency name="google-play-services-gcm"
    			if="google-play-services-gcm" />
    		<dependency name="google-play-services-iid"
    			if="google-play-services-iid" />

    Lastly, you need to setup each service from their websites and configure your app using each extension instruction.

    I hope all this helps you on your future android games!

  • Edited the guide because some user are having problems with latest google play services update. You can downgrade all dependecies to 9.0.0 but It won't work with latest google play services.

  • Hola Agustín, hice al pie de la letra tu tutorial pero no he logrado que funcione. El detalle es que mencionas el NDK r16b pero desde el sitio de descargas se consigue r15b.
    Por otro lado, que versión de JDK estás utilizando?

  • El ndk lo bajé de aca: https://developer.android.com/ndk/downloads/index.html
    Tal vez funciona el 15. No lo probé.

    Mi versión de java es jdk1.8.0_161

  • Hola Agustín, muchas gracias por responder. Probé con las versiones del JDK 1.6, la 1.7 y 1.8 pero no tuve suerte. La versión r16b no se consigue desde el link que facilitaste, es más desde allí podés ir hasta el historial de revisiones, la versión 16 es la primera de la lista y ofrece su descarga, accedes al link y te lleva al sitio de selección de descarga con versión 15... Cuak algo les pasó en el sitio.
    Mi juego compila y ejecuta hasta que intenta hacer login, ahí se rompe finalmente. Si tienes tiempo luego te muestro la forma en que intento la conexión por código.

    Muchas gracias!!!

  • ¿Te da error cuando intenta loguear a google play games? Yo tuve problemas por que no tenía bien seteados los permisos entre release y debug al hacer el app signing. Para el sign de la app te recomiendo leer: https://support.google.com/googleplay/android-developer/answer/7384423?hl=en

    Luego, tenes que configurar el sha-1 de la firma en google play services desde la google play console.

  • @agustín-pérez-fernández said in Tutorial on how to setup extensions with HaxeFlixel for mobile - Admob - Analytics - Google play games:


    Hola Agustin, muchas gracias por responder, voy a realizar la lectura del link que me pasas, quizás el sha1 que pasé es incorrecto. Por otro lado, para conseguir el NDK r16b la hice fácil, puse a descargar la versión 15, copié el vínculo, reemplacé el 5 por un 6 y salió una descarga de 801 Mb (cómo no se me ocurrió antes...).

    Realizo la lectura y corroboro las configuraciones, la firma y el sha-1 y te comento como me fue.
    Muchas gracias!!

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.