Problem with cocos helper Admob

Hello
I use Cocos helper to integrate Admob and my JS game. I follow the tutorial but when I run the command line “cocos compile -p android”. I got this error and libcocos2djs.so can not be buid.
In file included from jni/…/…/Classes/JNIResults.cpp:9:0:
jni/…/…/Classes/JNIResults.h:19:29: fatal error: SonarFrameworks.h: No such file or directory
#include “SonarFrameworks.h”

Please help me!
@SonarSystems

1 Like

Add SonarFrameworks files in Android.mk.

@anieduard
I follow series of tutorial http://sonarsystems.co.uk/cocoshelper.php?platform=android, and according to the tutorial “Setup for Android” , I just copy JNIResults.cpp and JNIResults.h to Classes folder, no SonarFrameworks files, can you give me more detail. Thanks so much!

You also have to add SonarFrameworks.js if you wrote your game in JavaScript and add the name of it in project.json like it is in the tutorial.

I added SonarFrameworks.js as well as change project,json. But the error tell me that, there was no
SonarFrameworks.h:. :frowning:

@SonarSystems, @Zinitter please help me !

Try to add SonarFrameworks.cpp and SonarFrameworks.h where you added JNIResults.cpp JNIResults.h.

hello
I tried to add SonarFrameworks.cpp and SonarFrameworks.h as well as add them in Android.mk. But somethings wrong still occur and eventually libcocos2djs.so can not be built. Have u tried to integrate Admob on Android, please teach me. thanks

Try changing #include “SonarFrameworks.h”
to
#include “jni/…/…/Classes/SonarFrameworks.h”

I tried, but still got this error:
"In file included from jni/…/…/Classes/JNIResults.cpp:9:0:
jni/…/…/Classes/JNIResults.h:19:47: fatal error: jni/…/…/Classes/SonarFrameworks.h: No such file or directory
#include “jni/…/…/Classes/SonarFrameworks.h” "

Can you teach me step by step how to integrate Admob, thanks u so much!

@Pantoo

If you want to use AdMob only, you can try read these tutorial.

For iOS

It is simple to integrate with iOS. If you don’t need iAd mediation, just don’t add the adapter.

For Android

It is a Japanese website, you can use google to translate the website into english.

You need to get “google-play-services.jar” with Android SDK Manager.
Then copy into /proj.android/libs/ and follow the tutorial.

I success to use AdMob with Cocos2d-JS v3.8.1

thank so much for your help, I m trying, but how can I show or hide admob ads by JS code in my GameScene ?
Also, can you give me step-by-step how to build JS game on android device tutorial ?
thanks again

@Pantoo

To control ads from JS, you need to use JS reflection

http://cocos2d-x.org/docs/manual/framework/html5/v3/reflection/en
http://cocos2d-x.org/docs/manual/framework/html5/v3/reflection-oc/en

Android, in AppActivity.java

Follow the tutorial and add static AppActivity _AppActivity;

public class AppActivity extends Cocos2dxActivity{

static AppActivity _AppActivity;

@Override
protected void onCreate(Bundle savedInstanceState) {

    _AppActivity = this;
}

public static void showAdMobBanner()
    {
        _AppActivity.runOnUiThread(new Runnable() {
            @Override
            public void run()
            {
                _adView.setVisibility(View.VISIBLE);
            }
        });
    }
    
    public static void hideAdMobBanner()
    {
        _AppActivity.runOnUiThread(new Runnable() {
            @Override
            public void run()
            {
                _adView.setVisibility(View.GONE);
           }
        });
    }

In JS, you call the function with these

var ret = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "showAdMobBanner", "()V");
var ret = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "hideAdMobBanner", "()V");

To build JS game on Android on Mac

I’m not sure the proper way to build, but since you ask, i just tell you how i build.

  1. Create JS project with Cocos.
  2. In Terminal, go to the project folder and use cocos compile -p android -m release to publish the apk. You need to create and specific where the keystore is. The apk can be found in publish folder.

You may need to use Google Closure Compiler to obfuscate your JS code.

cocos jscompile -s./Src -d ./ProjectName/src -c -o ProjectName.js -m "--jscomp_warning internetExplorerChecks"

Then change project.json

"jsList": ["src/ProjectName.js"]
1 Like

you shouldn’t need SonarFrameworks.h for JS.
I see in my project that I’m not using it, it’s only for C++.
JNIResult is calling native JAVA api…
you must have src/sonar/systems folder with the files.

2 Likes