Android SDKBOX: App crashes immediately on startup

I have followed the instructions here:
http://docs.sdkbox.com/en/plugins/iap/v3-cpp/
to manually integrate SDKBOX IAP. It is working fine on iOS.

Using:

  • Cocos2D-X 3.14.1
  • SDKBOX 2.3.12
  • Android Studio 2.3

The app crashes immediately on startup with:

java.lang.UnsatisfiedLinkError: No implementation found for void com.sdkbox.plugin.SDKBox.nativeInit(java.lang.Object, java.lang.ClassLoader) (tried Java_com_sdkbox_plugin_SDKBox_nativeInit and Java_com_sdkbox_plugin_SDKBox_nativeInit__Ljava_lang_Object_2Ljava_lang_ClassLoader_2)
    at com.sdkbox.plugin.SDKBox.nativeInit(Native Method)
    at com.sdkbox.plugin.SDKBox.init(SDKBox.java:71)
    at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:269)
    at android.app.Activity.performCreate(Activity.java:6876)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
    at android.app.ActivityThread.access$1100(ActivityThread.java:221)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7224)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

In my Application.mk, I am using:

APP_STL := c++_static

(Using gnustl_static is not an option, because many C++11 features that my code uses are missing with gnustl_static.)

I used the SDKBox libs from the android/jni/sdkbox/libs_c++_static folder to match.

I found this earlier forum post:


But that discussion does not seem to resolve the issue.

There is missing instruction in which you need to copy sdkbox_config.json file to build/jsb-default/frameworks/runtime-src/proj.android-studio/app/assets/res folder. With iOS you just need sdkbox_config.json in build/jsb-default/res folder

Hope this can help

Thanks for the suggestion. That didn’t help unfortunately: the above crash occurs before it gets to the stage of reading sdkbox_config.json.

java.lang.UnsatisfiedLinkError: No implementation found for void com.sdkbox.plugin.SDKBox.nativeInit(java.lang.Object, java.lang.ClassLoader) (tried Java_com_sdkbox_plugin_SDKBox_nativeInit and Java_com_sdkbox_plugin_SDKBox_nativeInit__Ljava_lang_Object_2Ljava_lang_ClassLoader_2)

From this it seems Java can’t find SDKBOX Java function or C++ function which is called from Java - check if all JAR’s are included into project and all C++ files was properly placed from static folder and is included in Android.mk - also before compile delete obj and libs folder in app folder to fully recompile project.

Also depends how you initialising plugin.

Thanks, yes I think the issue is that Java can’t find an SDKBOX C++ function which is called from Java.

Content of jni/Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos/audio/include)

LOCAL_MODULE := Test_shared

LOCAL_MODULE_FILENAME := libTest

LOCAL_SRC_FILES :=

(…)

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../src
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../include

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END

LOCAL_ARM_MODE := arm

LOCAL_CPPFLAGS += -DNO_STEAM

LOCAL_STATIC_LIBRARIES := cocos2dx_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

$(call import-add-path,$(LOCAL_PATH))

$(call import-module,.)
$(call import-module, ./sdkbox)
$(call import-module, ./pluginiap)

# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END

LOCAL_WHOLE_STATIC_LIBRARIES += PluginIAP
LOCAL_WHOLE_STATIC_LIBRARIES += sdkbox

Checking that the required symbol exists:

$ nm -g jni/sdkbox/libs/armeabi-v7a/libsdkbox.a |grep Java_com_sdkbox_plugin_SDKBox_nativeIni
00000000 T Java_com_sdkbox_plugin_SDKBox_nativeInit

The plugin is initialised in cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java:

protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.hideVirtualButton();
    onLoadNativeLibraries();
    SDKBox.init(this);

Is this Android.mk comes from Cocos studio?

I’m mostly using cocos2d-x C++ version and your Android.mk looks like very much customised - starting from lib names and source file location in src folder. It could be issue if u modified it.

Best way to try out is to create helloworld project and import there SDKBOX plugin to test - to see if there is any issue with your environment configuration or wrongly configured current project if hello world works.

BTW:
LOCAL_ARM_MODE := arm
Maybe this line is issue? according to google this parameter specify target ABI compile - as I remeber SDKBOX don’t have source files for ARM so it could be that why it can’t find this classes.

Yes, my Android.mk is customised.

I tried removing “LOCAL_ARM_MODE := arm” but still the same issue.

Tomorrow I’ll test with a helloworld project.

LOCAL_WHOLE_STATIC_LIBRARIES += PluginIAP
LOCAL_WHOLE_STATIC_LIBRARIES += sdkbox

before

LOCAL_STATIC_LIBRARIES := cocos2dx_static

example:

Thanks,
Jimmy

Yeah try to move LOCAL_WHOLE higher in Android.mk like @yinjimmy advicing

Thanks for your advice. After moving the LOCAL_WHOLE_STATIC_LIBRARIES lines above the LOCAL_STATIC_LIBRARIES, the build fails with these linker errors:

[armeabi-v7a] SharedLibrary  : libTest.so
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:4448: error: undefined reference to 'std::__1::__shared_weak_count::__release_shared()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:4448: error: undefined reference to 'std::__1::__shared_weak_count::__release_shared()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:479: error: undefined reference to 'std::__1::ios_base::getloc() const'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__locale:174: error: undefined reference to 'std::__1::locale::use_facet(std::__1::locale::id&) const'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:479: error: undefined reference to 'std::__1::locale::~locale()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:734: error: undefined reference to 'std::__1::ios_base::getloc() const'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__locale:174: error: undefined reference to 'std::__1::locale::use_facet(std::__1::locale::id&) const'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:734: error: undefined reference to 'std::__1::locale::~locale()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:524: error: undefined reference to 'std::__1::ios_base::clear(unsigned int)'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:494: error: undefined reference to 'std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >::id'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:494: error: undefined reference to 'std::__1::ctype<char>::id'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:508: error: undefined reference to 'std::__1::ios_base::getloc() const'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__locale:174: error: undefined reference to 'std::__1::locale::use_facet(std::__1::locale::id&) const'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:508: error: undefined reference to 'std::__1::locale::~locale()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:734: error: undefined reference to 'std::__1::ios_base::getloc() const'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__locale:174: error: undefined reference to 'std::__1::locale::use_facet(std::__1::locale::id&) const'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:734: error: undefined reference to 'std::__1::locale::~locale()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:524: error: undefined reference to 'std::__1::ios_base::clear(unsigned int)'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:520: error: undefined reference to 'std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >::id'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:520: error: undefined reference to 'std::__1::ctype<char>::id'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:668: error: undefined reference to 'std::__1::ios_base::init(void*)'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/streambuf:370: error: undefined reference to 'std::__1::locale::locale()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:668: error: undefined reference to 'std::__1::ios_base::init(void*)'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/streambuf:370: error: undefined reference to 'std::__1::locale::locale()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:4448: error: undefined reference to 'std::__1::__shared_weak_count::__release_shared()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:3639: error: undefined reference to 'std::__1::__shared_weak_count::~__shared_weak_count()'
/Users/krow/test/proj.android-studio/app/jni/./sdkbox/libs/armeabi-v7a/libsdkbox.a(Base64.o):Base64.cpp:typeinfo for std::__1::__shared_ptr_pointer<char*, std::__1::default_delete<char>, std::__1::allocator<char> >: error: undefined reference to 'typeinfo for std::__1::__shared_weak_count'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:4448: error: undefined reference to 'std::__1::__shared_weak_count::__release_shared()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:3639: error: undefined reference to 'std::__1::__shared_weak_count::~__shared_weak_count()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:4154: error: undefined reference to 'std::__1::__shared_weak_count::__add_shared()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:4154: error: undefined reference to 'std::__1::__shared_weak_count::__add_shared()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:4154: error: undefined reference to 'std::__1::__shared_weak_count::__add_shared()'
/Users/krow/test/proj.android-studio/app/jni/./sdkbox/libs/armeabi-v7a/libsdkbox.a(RequestManager.o):RequestManager.cpp:typeinfo for std::__1::__shared_ptr_pointer<sdkbox::XMLHttpRequest*, std::__1::default_delete<sdkbox::XMLHttpRequest>, std::__1::allocator<sdkbox::XMLHttpRequest> >: error: undefined reference to 'typeinfo for std::__1::__shared_weak_count'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:3639: error: undefined reference to 'std::__1::__shared_weak_count::~__shared_weak_count()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:4154: error: undefined reference to 'std::__1::__shared_weak_count::__add_shared()'
/Users/krow/test/proj.android-studio/app/jni/./sdkbox/libs/armeabi-v7a/libsdkbox.a(SdkboxCore.o):SdkboxCore.cpp:typeinfo for std::__1::__shared_ptr_pointer<sdkbox::AppLifeCycleListener*, std::__1::default_delete<sdkbox::AppLifeCycleListener>, std::__1::allocator<sdkbox::AppLifeCycleListener> >: error: undefined reference to 'typeinfo for std::__1::__shared_weak_count'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:524: error: undefined reference to 'std::__1::ios_base::clear(unsigned int)'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:524: error: undefined reference to 'std::__1::ios_base::clear(unsigned int)'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/istream:288: error: undefined reference to 'std::__1::ctype<char>::id'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:668: error: undefined reference to 'std::__1::ios_base::init(void*)'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/streambuf:370: error: undefined reference to 'std::__1::locale::locale()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:3639: error: undefined reference to 'std::__1::__shared_weak_count::~__shared_weak_count()'
/Users/krow/test/proj.android-studio/app/jni/./sdkbox/libs/armeabi-v7a/libsdkbox.a(XMLHttpRequest.o):XMLHttpRequest.cpp:typeinfo for std::__1::__shared_ptr_pointer<sdkbox::XMLHttpRequestListener*, std::__1::default_delete<sdkbox::XMLHttpRequestListener>, std::__1::allocator<sdkbox::XMLHttpRequestListener> >: error: undefined reference to 'typeinfo for std::__1::__shared_weak_count'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/streambuf:370: error: undefined reference to 'std::__1::locale::locale()'
jni/src/LogAndroid.cpp:58: error: undefined reference to 'std::__1::cout'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:661: error: undefined reference to 'std::__1::ios_base::~ios_base()'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:546: error: undefined reference to 'std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >::id'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:546: error: undefined reference to 'std::__1::ctype<char>::id'
/usr/local/Cellar/android-ndk/r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:668: error: undefined reference to 'std::__1::ios_base::init(void*)'
/Users/krow/test/proj.android-studio/app/jni/./pluginiap/libs_c++_static/armeabi-v7a/libPluginIAP.a(IAPWrapper.o):IAPWrapper.cpp:typeinfo for std::__1::basic_ios<char, std::__1::char_traits<char> >: error: undefined reference to 'typeinfo for std::__1::ios_base'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

/usr/local/Cellar/android-ndk/r10e does not exist locally. I’m using NDK r14b.

As suggested in this thread:
http://www.sdkbox.com/answers/question/c_static-support/
Tried adding -stdlib=libc++ to APP_LDFLAGS but that didn’t help.

Edit: In order to try a helloworld example, I tried the SDKBox IAP sample on Github, but encountered some other problems which I’ve described here:

Im using r10d …

Unfortunately there are other parts of my project that need a newer NDK release to compile, so downgrading to 10d isn’t an option for me.

I guess the problem is statically linking libraries that were linked to different NDK versions.

Maybe it would help if SDKBox was linked dynamically on Android. Would it be possible to get a libsdkbox.so as an alternative to the current libsdkbox.a?

It sounds like this can work, according to this Stackoverflow post:

am have u tried to delete obj/libs folders and recompile app?

Yes I’ve done gradle sync, clean builds and Android Studio Invalidate Caches/Restart, every time I’ve made a significant change.