[SOLVED] ReferenceError: sdkbox is not defined

[SOLVED] ReferenceError: sdkbox is not defined
0.0 0

#1

Hi,
sdkbox installer ran fine with no errors, but I keep on getting the following error when trying to initialize the Chartboost plug-in (sdkbox.PluginChartboost.init();):

JS: /data/data/org.cocos2dx.PrebuiltRuntimeJs/files/debugruntime/src/MenuLayer.js:10:ReferenceError: sdkbox is not defined

I’d appreciate your help,
Thanks

I’m running Cocos2d-js 3.6.1


#2

Same with cocos framework 3.7

Edit: SOLVED!

forget about AppDelegate.cpp

ex: Rate Review sdk integration on JS

Put the include references on js_module_register.h file
#include “PluginReviewJS.hpp”
#include “PluginReviewJSHelper.h”

Put the register callbacks inside int js_module_register()
// SDKBOX
sc->addRegisterCallback(register_all_PluginReviewJS);
sc->addRegisterCallback(register_all_PluginReviewJS_helper);


#3

Thanks for your reply.
Where is js_module_register.h supposed to be located? I can’t find it.
I assumed it’d be in here .\frameworks\runtime-src\Classes


#4

It should be, it is for me…


#5

For 3.6.1 you have to add it to AppDelegate.cpp


#6

I added it to AppDelegate.cpp as indicated here http://sdkbox-doc.github.io/en/plugins/chartboost/v3-js/, but it always comes back with sdkbox is not defined.
I’m using the cocos IDE 1.2, I don’t know if that would matter.
My game compiles and runs fine, everything works, except for this, as soon as try to start sdkbox it fails, what’s wrong with it?

This is my AppDelegate.cpp:

#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"


#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

#include "CodeIDESupport.h"
#include "Runtime.h"
#include "ConfigParser.h"

//Chartboost
#include "PluginChartboostJS.hpp"
#include "PluginChartboostJSHelper.h"

USING_NS_CC;
using namespace CocosDenshion;

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate()
{
    ScriptEngineManager::destroyInstance();
#if (COCOS2D_DEBUG > 0 && CC_CODE_IDE_DEBUG_SUPPORT > 0)
	// NOTE:Please don't remove this call if you want to debug with Cocos Code IDE
	endRuntime();
#endif

	ConfigParser::purge();
}

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

bool AppDelegate::applicationDidFinishLaunching()
{
#if (COCOS2D_DEBUG > 0 && CC_CODE_IDE_DEBUG_SUPPORT > 0)
    // NOTE:Please don't remove this call if you want to debug with Cocos Code IDE
    initRuntime();
#endif
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();    
    if(!glview) {
        Size viewSize = ConfigParser::getInstance()->getInitViewSize();
        string title = ConfigParser::getInstance()->getInitViewName();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) && (COCOS2D_DEBUG > 0 && CC_CODE_IDE_DEBUG_SUPPORT > 0)
        extern void createSimulator(const char* viewName, float width, float height,bool isLandscape = true, float frameZoomFactor = 1.0f);
        bool isLanscape = ConfigParser::getInstance()->isLanscape();
        createSimulator(title.c_str(), viewSize.width,viewSize.height, isLanscape);
#else
        glview = cocos2d::GLViewImpl::createWithRect(title.c_str(), Rect(0, 0, viewSize.width, viewSize.height));
        director->setOpenGLView(glview);
#endif
    }

    // 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);

    // 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);
	
	//Chartboost
	sc->addRegisterCallback(register_all_PluginChartboostJS);
	sc->addRegisterCallback(register_all_PluginChartboostJS_helper);
    
#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
    
#if (COCOS2D_DEBUG > 0 && CC_CODE_IDE_DEBUG_SUPPORT > 0)
    // NOTE:Please don't remove this call if you want to debug with Cocos Code IDE
    startRuntime();
#else
    sc->start();
    sc->runScript("script/jsb_boot.js");
    auto engine = ScriptingCore::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(engine);
    ScriptingCore::getInstance()->runScript(ConfigParser::getInstance()->getEntryFile().c_str());
#endif
    
    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();
}

#7

That looks correct, if you’re using IDE with simulator, make sure you recompile the simulator


#8

Thanks @nite


#9

I am facing the same problem. @nite What do u mean by recompiling the simulator?


#10

I tried doing this but it didn’t work for me :frowning: I have more details and questions here: How to make sure Flurry is set up properly?


#11

I am also using cocos 3.7 but this solution did not work for me :frowning:

I am trying to get Flurry Analytics working in my project so I put

#include "PluginFlurryAnalyticsJS.hpp"
#include "PluginFlurryAnalyticsJSHelper.h"

in both AppDelegate.cpp AND in js_module_register.h and also did

// Flurry Analytics
sc->addRegisterCallback(register_all_PluginFlurryAnalyticsJS);
sc->addRegisterCallback(register_all_PluginFlurryAnalyticsJS_helper);

in both files after js_module_register();

But no luck, still getting ReferenceError: sdkbox is not defined.


#12

Is it possible for us to access your project and see what’s wrong?


#13

My project is on BitBucket. If you have a username on there or an email you want me to send the repo to then I can share the project that way.


#14

You can share the project with nite@sdkbox.com


#15

Did you get the invite to the repo?
Please let me know if you had a chance to look at it.

@pabitrapadhy I have tried looking at https://github.com/sdkbox/sdkbox-flurry-sample but found no difference from my project and the sample one in terms of integrating Flurry analytics.

Thanks.


#16

still looking at it, will update you later today


#17

I wasn’t able to compile your project


#18

Hmmmm.
I will try redoing the JavaScript Helper Setup tutorials and SDKBOX Installer again to see if I missed anything.


#19

So I tried your sample, looks like flurry is been called

Flurry: startSession has been called already. It should only be called once. Returning.

#20

Thanks for trying out my sample.
It seems like I’ve been getting the ReferenceError: sdkbox is not defined. only when I try to run the project on Web. I ran it on Xcode simulator and got the same log message as you did.

If you uncomment all the sdkbox calls from the app.js file, am I placing the calls correctly?
How/where do I set the Flurry init() call to run just once?