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 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.
This is the list of all the libraries once installed. You can look your list doing:
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] lime:[2.9.1] 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
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/
For admob and Google play install the extensions from Haxelib. I’m using the following versions:
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:
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:
google-play-services-ads-lite google-play-services-analytics google-play-services-analytics-impl google-play-services-auth google-play-services-base google-play-services-basement google-play-services-drive google-play-services-games google-play-services-gcm google-play-services-iid google-play-services-plus
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"/> <application> <!-- Optionally, register AnalyticsReceiver and AnalyticsService to support background dispatching on non-Google Play devices --> <receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver" android:enabled="true"> <intent-filter> <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" /> </intent-filter> </receiver> <service android:name="com.google.android.gms.analytics.AnalyticsService" android:enabled="true" android:exported="false"/> <!-- Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable installation campaign reporting --> <receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver" android:exported="true"> <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver> <service android:name="com.google.android.gms.analytics.CampaignTrackingService" /> </application> <application/> </manifest>
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"?> <extension> <section if="android"> <dependency name="google-play-services-basement" path="dependencies/google-play-services-basement" if="google-play-services-basement" /> <dependency name="google-play-services-ads-lite" path="dependencies/google-play-services-ads-lite" if="google-play-services-ads-lite" /> <dependency name="google-play-services-auth" path="dependencies/google-play-services-auth" if="google-play-services-auth" /> <dependency name="google-play-services-base" path="dependencies/google-play-services-base" if="google-play-services-base" /> <dependency name="google-play-services-drive" path="dependencies/google-play-services-drive" if="google-play-services-drive" /> <dependency name="google-play-services-plus" path="dependencies/google-play-services-plus" if="google-play-services-plus" /> <dependency name="google-play-services-games" path="dependencies/google-play-services-games" if="google-play-services-games" /> <dependency name="google-play-services-gcm" path="dependencies/google-play-services-gcm" if="google-play-services-gcm" /> <dependency name="google-play-services-analytics" path="dependencies/google-play-services-analytics" if="google-play-services-analytics" /> <dependency name="google-play-services-analytics-impl" path="dependencies/google-play-services-analytics-impl" if="google-play-services-analytics-impl" /> <dependency name="google-play-services-gcm" path="dependencies/google-play-services-gcm" if="google-play-services-gcm" /> <dependency name="google-play-services-iid" path="dependencies/google-play-services-iid" if="google-play-services-iid" /> </section> </extension>
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!