Cocos2d-js : How to integrate AdMob for Android - Part 2
- Mac OS X Yosemite
- python 2.7
- java jdk 1.7.0_71
- android-ndk-r10c
- cocos2d-js-v3.2
- apache-ant-1.9.4
- cocos code ide 1.2.0
For debug:
- adt-bundle-mac-x86_64-20140702
Here we go, after you completed Part 1
link: http://gamedevtodied.blogspot.com/2015/02/cocos2d-js-how-to-integrate-admob-for.html
link: http://gamedevtodied.blogspot.com/2015/02/cocos2d-js-how-to-integrate-admob-for.html
The next step is begin to working with plugin-x and we need "AdMob" plugin but it's need to build them before you can use it.
[Build Plugin-X]
1. open Finder and browse to [yourProjectFolder] for sample is "CocosJsAdMob32" goto this path"CocosJsAdMob32/frameworks/js-bindings/cocos2d-x/plugin/tools"
2. open Terminal then type cd and drag tools folder and release on Terminal OR copy path and place after cd command and press "Enter" as below image.
sample "cd /Users/poraweeraksasin/Documents/cocos/CocosJsAdMob32/frameworks/js-bindings/cocos2d-x/plugin/tools"
3. type "sh publish.sh " then press "Enter".
5. it's has a prompt "Please input the android-sdk path:", so you just drag "adt-bundle-mac-xxx/sdk" folder and release here on Terminal and remove space after path then press "Enter".
6. it's has a prompt "Please input the ant tool path(such as '/Users/MyAccount/tools/ant/bin'):", so you just drag "apache-ant-xxx/bin" folder and release here on Terminal and remove space after path then press "Enter". After that it's take a long time for publish every plugin.
7. when process was done it's will be back to command prompt, you can check by scroll back to see on step AdMob publish, is it success? as "Now publish admob" and "BUILD SUCCESSFUL".
[Add Plugin-X]
Manual Modification
1. open "AppDelegate.cpp" with text editor, it's place in "[yourProject]/frameworks/runtime-src/Classes" then add below section into file as sample image.
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "jsb_cocos2dx_pluginx_auto.hpp"
#include "jsb_pluginx_extension_registration.h"
#endif
2. we're still in "AppDelegate.cpp" add more line of code as sample image.
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
sc->addRegisterCallback(register_all_pluginx_protocols);
sc->addRegisterCallback(register_pluginx_js_extensions);
#endif
3. open "AndroidManifest.xml" with text editor, it's place in "[yourProject]/frameworks/runtime-src/proj.android", add add more activity for admob like below image.
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
4. open "build-cfg.json" with text editor, it's place in "[yourProject]/frameworks/runtime-src/proj.android".
place this line "../../js-bindings/cocos2d-x/plugin/publish"
in section "ndk_module_path"
and place "
{
"from": "../../js-bindings/cocos2d-x/plugin/jsbindings/script",
"to": ""
},
{
"from": "../../js-bindings/cocos2d-x/plugin/protocols/proj.android/src",
"to": "../src"
},
{
"from": "../../js-bindings/cocos2d-x/plugin/plugins/admob/proj.android/src",
"to": "../src"
},
{
"from": "../../js-bindings/cocos2d-x/plugin/plugins/admob/proj.android/sdk",
"to": "../libs"
}
" in section "copy_resources", see a sample 4.
5. open "Android.mk" with text editor, it's place in "[yourProject]/frameworks/runtime-src/proj.android/jni". see sample 5 where the line add code
LOCAL_STATIC_LIBRARIES := cocos_jsb_static
LOCAL_WHOLE_STATIC_LIBRARIES += jsb_pluginx_static << add this line.
$(call import-module,bindings)
$(call import-module,cocos2d-x/plugin/jsbindings) << add this line
sample 5.
6. open "main.cpp" with text editor, it's place in "[yourProject]/frameworks/runtime-src/proj.android/jni/hellojavascript".
add
#include "PluginJniHelper.h"
and
JavaVM* vm;
env->GetJavaVM(&vm);
PluginJniHelper::setJavaVM(vm);
3. i insert usb cable from your Android Phone to Mac usb port, when packaging it success, you should see,
Packaging success
the package saved to /User/poraweeraksasin/Documents/cocos/CocosJsAdMob32/publish/android
see on "Devices:" the name of your mobile devices will appear here, if not just press "Refresh", then click "Install", if anything are ok, the console will show message as below.
install APK start...Install APK success
4. open your Android phone, brought to find app icon "CocosJsAdMob",
It's work.
is it the end? No! next part i will show you about debug AdMob
--------------
Create Admob and Cocos2d-js project from Part 1:
http://gamedevtodied.blogspot.com/2015/02/cocos2d-js-how-to-integrate-admob-for.html
Debug Admob and Run or Build Apk with eclipse adt-bundle-mac from Part 3 END:
http://gamedevtodied.blogspot.com/2015/02/cocos2d-js-how-to-integrate-admob-for_16.html
and place "
{
"from": "../../js-bindings/cocos2d-x/plugin/jsbindings/script",
"to": ""
},
{
"from": "../../js-bindings/cocos2d-x/plugin/protocols/proj.android/src",
"to": "../src"
},
{
"from": "../../js-bindings/cocos2d-x/plugin/plugins/admob/proj.android/src",
"to": "../src"
},
{
"from": "../../js-bindings/cocos2d-x/plugin/plugins/admob/proj.android/sdk",
"to": "../libs"
}
" in section "copy_resources", see a sample 4.
sample 4.
5. open "Android.mk" with text editor, it's place in "[yourProject]/frameworks/runtime-src/proj.android/jni". see sample 5 where the line add code
LOCAL_STATIC_LIBRARIES := cocos_jsb_static
LOCAL_WHOLE_STATIC_LIBRARIES += jsb_pluginx_static << add this line.
$(call import-module,bindings)
$(call import-module,cocos2d-x/plugin/jsbindings) << add this line
sample 5.
6. open "main.cpp" with text editor, it's place in "[yourProject]/frameworks/runtime-src/proj.android/jni/hellojavascript".
add
and
JavaVM* vm;
env->GetJavaVM(&vm);
PluginJniHelper::setJavaVM(vm);
7. open "AppActivity.java" with text editor, it's place in "[yourProject]/frameworks/runtime-src/proj.android/src/org/cocos2dx/javascript/".
add
import org.cocos2dx.plugin.PluginWrapper;
and
PluginWrapper.init(this);
PluginWrapper.setGLSurfaceView(glSurfaceView);
see sample 7.
8. back to cocos code ide from project open "[projectName]/src/app.js" and call admob plugin as below code
var AdMob = plugin.PluginManager.getInstance().loadPlugin("AdsAdmob");
var m = {
"AdmobID" : "ca-app-pub-0000000000000000/0000000000", // your admob id from part 1
"AdmobType" : "1",
"AdmobSizeEnum" : "1"
};
AdMob.configDeveloperInfo(m);
AdMob.showAds(m, 1);
8. back to cocos code ide from project open "[projectName]/src/app.js" and call admob plugin as below code
var AdMob = plugin.PluginManager.getInstance().loadPlugin("AdsAdmob");
var m = {
"AdmobID" : "ca-app-pub-0000000000000000/0000000000", // your admob id from part 1
"AdmobType" : "1",
"AdmobSizeEnum" : "1"
};
AdMob.configDeveloperInfo(m);
AdMob.showAds(m, 1);
see sample 8.
[Publish AdMob for Android]
1. let's export Apk, right-click on project name then goto Cocos Tools > Package to APK for Android.

2. setting as below image and click "Generate >"
- check "Publish with debug keystore"
- Android SDK Version "android-14"
- other leave as default

3. i insert usb cable from your Android Phone to Mac usb port, when packaging it success, you should see,
Packaging success
the package saved to /User/poraweeraksasin/Documents/cocos/CocosJsAdMob32/publish/android
see on "Devices:" the name of your mobile devices will appear here, if not just press "Refresh", then click "Install", if anything are ok, the console will show message as below.
install APK start...Install APK success
4. open your Android phone, brought to find app icon "CocosJsAdMob",
<!> Don't forget to open mobile internet as WIFI/3G/4G, if not so will never see ads <!>
and
<!> Don't tap Ads because you was Banned from Google as boost tap cheat <!>
then tap to launch game manually, you should see AdMob display on top-center of screen by landscape orientation.
It's work.
is it the end? No! next part i will show you about debug AdMob
--------------
Create Admob and Cocos2d-js project from Part 1:
http://gamedevtodied.blogspot.com/2015/02/cocos2d-js-how-to-integrate-admob-for.html
Debug Admob and Run or Build Apk with eclipse adt-bundle-mac from Part 3 END:
http://gamedevtodied.blogspot.com/2015/02/cocos2d-js-how-to-integrate-admob-for_16.html















Comments
Post a Comment