Jmonkey 3.1 + AdMob + Google play services

Hi, can someone provide working example how to add support for google APIs because recently there are alot of changes in google android sdk and this instruction does not work for me →

The biggest problem is that google’s play services and admob is now converted to use the gradle build system.

My suggestion and this is still a work in progress, is to create your game in jME3.1 sdk.
Then when you have a working game that is running on PC I would open up Android Studio.

I would create a SimpleAndroidApplication with only one activity.
Change that activity to look like the one jME generates. Taking into account you add all resources needed.
Also make sure you add the android project at the same file path as the jME game.

Then in the android app’s build.gradle file, change the script to add the following:

  1. Add the google play services dependency to the gradle script
  2. Add the admob dependency to the gradle script
  3. Add a task to copy all the jME generated jar’s in the games dist folder. (…GamePath/dist/libs) “NB: Exclude the generated assets.jar”
  4. Add a task to copy the game jar generated by jME. (…GamePath/dist/mygame.jar)
  5. Add a task that will copy the Assest folder of your game to android.

I think that is the basic idea and I am sure you can use it to get started. Good luck!

Here is my build.gradle file:

apply plugin: ''

ext {
    gamePath = "../../Driver-Game"
    gameJar = "OneTouchDriving.jar"

android {
    signingConfigs {
        bruynhuiskey {
            keyAlias 'xxx'
            keyPassword 'xxx'
            storeFile file('C:/workspaces/privatework/gitprojects/bruynhuisandroidstudio/bruynhuis-key')
            storePassword 'xxx'
    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    defaultConfig {
        applicationId "com.bruynhuis.driver"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 3
        versionName "1.2"
        multiDexEnabled true
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
    productFlavors {

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile ''
    compile ''
    compile ''

task ClearGameJar(type: Delete) {
    delete 'libs/' + gameJar

task copyGameJar(type: Copy) {
    from gamePath + '/dist/' + gameJar
    into 'libs'

task ClearJMEJars(type: Delete) {
    delete fileTree('libs') {
        include '**/*.jar'

task copyJMEJars(type: Copy) {
    from(gamePath + '/dist/lib') {
        include '*.jar'
        exclude 'jME3-desktop.jar'
        exclude 'assets.jar'
    into 'libs'

task clearAssets(type: Delete) {
    delete 'src/main/assets'

task copyAssets(type: Copy) {
    from(gamePath+'/assets') {
        include '**/*.*'
    into 'src/main/assets/'

project.afterEvaluate {
    prepareDebugDependencies.dependsOn(ClearJMEJars, ClearGameJar, clearAssets, copyJMEJars, copyGameJar, copyAssets)
1 Like

Well thanks for replay i will continue the struggle with this overkill suggestion ( not saying its bad its only sensible approach :slight_smile: ). I will post what i did to run banner (hope this will run when i published it on playstore)
Btw this is test add Unit id from github project of admob.

Added google-play-services.jar to my jmonkey project from this version of google play services:

This is what looks like in MainActivity

import android.widget.LinearLayout;
import android.view.Gravity;
import android.view.ViewGroup;

protected void onCreate(Bundle savedInstanceState) {
// Set window fullscreen and remove title bar

    //added buy me 
    // Initialize the Mobile Ads SDK.
    adView = new AdView(this);
    LinearLayout ll = new LinearLayout(this);
    addContentView(ll, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    AdRequest.Builder builder = new AdRequest.Builder();
    AdRequest request =;

    // find the fragment
    FragmentManager fm = getFragmentManager();
    AndroidHarnessFragment jmeFragment
            = (AndroidHarnessFragment) fm.findFragmentById(;

    // uncomment the next line to add the default android profiler to the project
    //jmeFragment.getJmeApplication().setAppProfiler(new DefaultAndroidProfiler());

Android Manifest in application tag element (missing <):
meta-data android:name=“” android:value="@string/app_id" />

meta-data android:name=“” android:value="@integer/google_play_services_version"/>

activity android:name=“” android:configChanges=“keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize”/>

And in manifest tag element (missing <)

uses-permission android:name="android.permission.INTERNET"/>
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
1 Like

Could you please post how do you save/retrieve google_play_services_version?


it was somewhere in this folder /google-play-services/libproject/google-play-services_lib/res/

1 Like

I still have some issues. Code gives no error/exceptions but AD won’t show. Tried waiting some minutes but it seems to not be loaded.

I used addTestDevice and those are logs from I/Ads:

I/Ads ( 9803): Starting ad request. I/Ads ( 9803): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad. I/Ads ( 1129): Received log message: <Google:HTML> You are using version 8.3 of the Google Play Services Ads SDK. Please consider updating your SDK to the most recent SDK version to get the latest features and bug fixes. See for instructions on how to get the latest version of Google Play services. I/Ads ( 9803): Scheduling ad refresh 60000 milliseconds from now. I/Ads ( 9803): Ad finished loading.

EDIT: Solved using AdSize.SMART_BANNER

have you managed to run play games services with this version of jar?

Yes,i’m using the one you linked.

can u post how u run play game service

Downloaded the jar and imported in in the project as a library,no more.
I don’t think we are talking about the same library anyway,i’m talking about the jar you linked in the post above.