Sdkbox is not defined!

Hello!
I’ve created new project v3.10 with some plugins using Cocos Studio.
After that I compile my project using “cmd” for Android Studio. But when I run the project on my device I have this error: assets/src/menu.js:17:TypeError: sdkbox is undefined
Help!

Hello @oleg_karman

Have you tried adding your plugins present inside your proj.android-studio/app/jni as dependency inside your Android Studio project. !!

Yes! When I add services using “cmd” through “sdkbox import plugin_name” everything works great, but when I add them through Cocos Studio I have the error “sdkbox is undefined”.

Yes, because Cocos Studio currently won’t auto inject integration code for you. I would recommend using command line for now.

Ok! Thank you!

Could you help me with another problem?
I successfully added some plugins like ChartBoost, Facebook and ADColony and they work good. But when I try to initialize Google Analytics with “sdkbox.PluginGoogleAnalytics.init();” I always have an error “sdkbox.PluginGoogleAnalytics is not defined”.

Hello @oleg_karman

Please check the Usage section of the documentation here.
I guess you are missing some listeners.

http://docs.sdkbox.com/en/plugins/googleanalytics/v3-js/

Best,
Pabitra

Usually not defined problem is caused by missing register code in AppDelegate.cpp, it would be great if you can post your AppDelegate.cpp so we can take a look.

AppDelegate.cpp (9.1 KB)

#include "AppDelegate.h"

#include "SimpleAudioEngine.h"
#include "jsb_cocos2dx_auto.hpp"
#include "jsb_cocos2dx_ui_auto.hpp"
#include "jsb_cocos2dx_studio_auto.hpp"
#include "jsb_cocos2dx_builder_auto.hpp"
#include "jsb_cocos2dx_spine_auto.hpp"
#include "jsb_cocos2dx_extension_auto.hpp"
#include "jsb_cocos2dx_3d_auto.hpp"
#include "jsb_cocos2dx_3d_extension_auto.hpp"
#include "3d/jsb_cocos2dx_3d_manual.h"
#include "ui/jsb_cocos2dx_ui_manual.h"
#include "cocostudio/jsb_cocos2dx_studio_manual.h"
#include "cocosbuilder/js_bindings_ccbreader.h"
#include "spine/jsb_cocos2dx_spine_manual.h"
#include "extension/jsb_cocos2dx_extension_manual.h"
#include "localstorage/js_bindings_system_registration.h"
#include "chipmunk/js_bindings_chipmunk_registration.h"
#include "jsb_opengl_registration.h"
#include "network/XMLHTTPRequest.h"
#include "network/jsb_websocket.h"
#include "network/jsb_socketio.h"
#include "jsb_cocos2dx_physics3d_auto.hpp"
#include "physics3d/jsb_cocos2dx_physics3d_manual.h"
#include "jsb_cocos2dx_navmesh_auto.hpp"
#include "navmesh/jsb_cocos2dx_navmesh_manual.h"
//GA
#include "PluginGoogleAnalyticsJS.hpp"

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||         CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#include "jsb_cocos2dx_experimental_video_auto.hpp"
#include "experimental/jsb_cocos2dx_experimental_video_manual.h"
#include "jsb_cocos2dx_experimental_webView_auto.hpp"
#include "experimental/jsb_cocos2dx_experimental_webView_manual.h"
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT ||     CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#include "jsb_cocos2dx_audioengine_auto.hpp"
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "platform/android/CCJavascriptJavaBridge.h"
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
#include "platform/ios/JavaScriptObjCBridge.h"
#endif

#ifdef SDKBOX_ENABLED
#include "PluginChartboostJS.hpp"
#include "PluginChartboostJSHelper.h"
#endif
#ifdef SDKBOX_ENABLED
#include "PluginKochavaJS.hpp"
//#include "PluginKochavaJSHelper.h"
#endif
#ifdef SDKBOX_ENABLED
#include "PluginFacebookJS.hpp"
#include "PluginFacebookJSHelper.h"
#endif
#ifdef SDKBOX_ENABLED
#include "PluginAdColonyJS.hpp"
#include "PluginAdColonyJSHelper.h"
#endif
#ifdef SDKBOX_ENABLED
#include "PluginIAPJS.hpp"
#include "PluginIAPJSHelper.h"
#endif
#ifdef SDKBOX_ENABLED
#include "PluginAchievementJS.hpp"
#include "PluginAchievementJSHelper.h"
#endif
#ifdef SDKBOX_ENABLED
#include "PluginLeaderboardJS.hpp"
#include "PluginLeaderboardJSHelper.h"
#endif
USING_NS_CC;
using namespace CocosDenshion;

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate()
{
    ScriptEngineManager::destroyInstance();
}

void AppDelegate::initGLContextAttrs()
{
    GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};

    GLView::setGLContextAttrs(glContextAttrs);
}

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if(CC_TARGET_PLATFORM == CC_PLATFORM_WP8) ||     (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
        glview = cocos2d::GLViewImpl::create("MiningTime");
#else
        glview =     cocos2d::GLViewImpl::createWithRect("MiningTime",     Rect(0,0,960,640));
#endif
        director->setOpenGLView(glview);
}

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    ScriptingCore* sc = ScriptingCore::getInstance();
    sc->addRegisterCallback(register_all_cocos2dx);
    sc->addRegisterCallback(register_cocos2dx_js_core);
    sc->addRegisterCallback(jsb_register_system);

    //GA
    sc->addRegisterCallback(register_all_PluginGoogleAnalyticsJS);

   // extension can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_extension);
    sc->addRegisterCallback(register_all_cocos2dx_extension_manual);

    // chipmunk can be commented out to reduce the package
    sc->addRegisterCallback(jsb_register_chipmunk);
    // opengl can be commented out to reduce the package
    sc->addRegisterCallback(JSB_register_opengl);

    // builder can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_builder);
    sc->addRegisterCallback(register_CCBuilderReader);

    // ui can be commented out to reduce the package, attension studio need ui module
    sc->addRegisterCallback(register_all_cocos2dx_ui);
    sc->addRegisterCallback(register_all_cocos2dx_ui_manual);

    // studio can be commented out to reduce the package, 
    sc->addRegisterCallback(register_all_cocos2dx_studio);
sc->addRegisterCallback(register_all_cocos2dx_studio_manual);

    // spine can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_spine);
    sc->addRegisterCallback(register_all_cocos2dx_spine_manual);

    // XmlHttpRequest can be commented out to reduce the package
    sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
    // websocket can be commented out to reduce the package
    sc->addRegisterCallback(register_jsb_websocket);
    // sokcet io can be commented out to reduce the package
    sc->addRegisterCallback(register_jsb_socketio);

    // 3d can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_3d);
    sc->addRegisterCallback(register_all_cocos2dx_3d_manual);

    // 3d extension can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_3d_extension);

#if CC_USE_3D_PHYSICS &&     CC_ENABLE_BULLET_INTEGRATION
    // Physics 3d can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_physics3d);
    sc->addRegisterCallback(register_all_cocos2dx_physics3d_manual);
#endif

#if CC_USE_NAVMESH
    sc->addRegisterCallback(register_all_cocos2dx_navmesh);
    sc->addRegisterCallback(register_all_cocos2dx_navmesh_manual);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||     CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    sc->addRegisterCallback(register_all_cocos2dx_experimental_video);
    sc->addRegisterCallback(register_all_cocos2dx_experimental_video_manual);
    sc->addRegisterCallback(register_all_cocos2dx_experimental_webView);
    sc->addRegisterCallback(register_all_cocos2dx_experimental_webView_manual);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
    sc->addRegisterCallback(register_all_cocos2dx_audioengine);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
     sc->addRegisterCallback(JavascriptJavaBridge::_js_register);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    sc->addRegisterCallback(JavaScriptObjCBridge::_js_register);
#endif
#ifdef SDKBOX_ENABLED
    sc->addRegisterCallback(register_all_PluginChartboostJS);
    sc->addRegisterCallback(register_all_PluginChartboostJS_helper);
#endif
#ifdef SDKBOX_ENABLED
    sc->addRegisterCallback(register_all_PluginKochavaJS);
//    sc->addRegisterCallback(register_all_PluginKochavaJS_helper);
#endif
#ifdef SDKBOX_ENABLED
    sc->addRegisterCallback(register_all_PluginFacebookJS);
    sc->addRegisterCallback(register_all_PluginFacebookJS_helper);
#endif
#ifdef SDKBOX_ENABLED
    sc->addRegisterCallback(register_all_PluginAdColonyJS);
    sc->addRegisterCallback(register_all_PluginAdColonyJS_helper);
#endif
#ifdef SDKBOX_ENABLED
    sc->addRegisterCallback(register_all_PluginIAPJS);
    sc->addRegisterCallback(register_all_PluginIAPJS_helper);
#endif
#ifdef SDKBOX_ENABLED
    sc->addRegisterCallback(register_all_PluginAchievementJS);
    sc->addRegisterCallback(register_all_PluginAchievementJS_helper);
#endif
#ifdef SDKBOX_ENABLED
    sc->addRegisterCallback(register_all_PluginLeaderboardJS);
    sc->addRegisterCallback(register_all_PluginLeaderboardJS_helper);
 #endif
    sc->start();    
    sc->runScript("script/jsb_boot.js");
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
     sc->enableDebugger();
#endif
    ScriptEngineProtocol *engine = ScriptingCore::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(engine);
    ScriptingCore::getInstance()->runScript("main.js");

    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    auto director = Director::getInstance();
    director->stopAnimation();
    director->getEventDispatcher()->dispatchCustomEvent("game_on_hide");
    SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
    SimpleAudioEngine::getInstance()->pauseAllEffects();    
 }

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    auto director = Director::getInstance();
    director->startAnimation();
    director->getEventDispatcher()->dispatchCustomEvent("game_on_show");
    SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
    SimpleAudioEngine::getInstance()->resumeAllEffects();
 }

Ok, I found the solution for me. I just had to add Google Analytics plugin through “cmd” ,but after all other plugins.
Still I have problem. I got “trackingCode” and I added it to my “sdkbox_config.json”. After this I create a button and put function on it:
playButton: function () {
sdkbox.PluginGoogleAnalytics.logEvent(“MiningTime”,“Game”,“Play”,1);
var scene = new JevelMinerScene();
playAnimation(“Main_Menu_Outro”, animationMovie, false);
cc.director.runScene(new cc.TransitionFade(1.2, scene));
}
I should receive an event on my GoogleAnalytics account, but there is none.
Also I put event after google.init() :
sdkbox.PluginGoogleAnalytics.init();
sdkbox.PluginGoogleAnalytics.startSession();
sdkbox.PluginGoogleAnalytics.enableTracker(“XX-YYYYYYYY-Z”);
sdkbox.PluginGoogleAnalytics.logEvent(“MiningTime”,“Game”,“GameStarted”,1);
but still nothing.

  • Please use the dispatchHits() callback to register the event.
  • Please try once again without changing into next scene, it might be possible that as you are replacing the scene, the listeners are destroyed and your event is not registered.

Best,
Pabitra

Ok I will try, but what about the event that I call immediately after initialisation?
I also have no respond for this event.

Note google analytics will batch events and send them every 5 mins by default. so dsipatchHits() is only recommended for testing usage.

I understand. I used dsipatchHits() like this :
sdkbox.PluginGoogleAnalytics.logEvent("MiningTime","Game","GameOver",1); sdkbox.PluginGoogleAnalytics.dsipatchHits();

and also I tried to use quick dispatch every 10 seconds :

sdkbox.PluginGoogleAnalytics.logEvent("MiningTime","Game","GameOver",1); sdkbox.PluginGoogleAnalytics.dispatchPeriodically(10);

without changing scene, but I receive nothing.

I also tried sample from
https://github.com/sdkbox/sdkbox-sample-ga/blob/master/js/src/app.js
where I just put my tracking code and google-services.json into my app\ folder and there is no respond
: (

Could you please cross-check your app with this sample -
https://github.com/sdkbox/sdkbox-ga-sample

If still not working, then may I look at your project source, you may PM me a link to it.

I have no opportunity to check this sample because I have an error and I can’t compile the project.

About source, you mean you want to see my JS files?

Please let us know the version of sdkbox you are using.

Yes, please send a mail at support@sdkbox.com we would try to debug the issue with the app.

I send to you an email.
Thank you for your help.

I found that running app on my android device caused few errors:

02-17 17:47:56.277 7504-7590/com.ArtBit.Analytics E/dalvikvm: Could not find class 'android.support.v4.app.NotificationCompat$Builder', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza

02-17 17:47:56.277 7504-7590/com.ArtBit.Analytics E/dalvikvm: Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza

02-17 17:47:56.278 7504-7590/com.ArtBit.Analytics E/dalvikvm: Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza

02-17 17:47:56.284 7504-7590/com.ArtBit.Analytics E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzb

That is why I don’t receive any data on my GA account. I think that it caused by API version of my device(16), because when I am running it on emulator with API higher than 19 I begin to receive data.
Is there any suggestion what should I do?