SDKBox IAP example not working with modern API level, or Android Studio

Using OS X 10.12.4 and Android Studio 2.3.1.

Steps to reproduce:

git clone https://github.com/sdkbox/sdkbox-sample-iap.git
cd sdkbox-sample-iap
./setup
cd cpp
cocos run -p android -m release

The last command gives this error:

Building mode: release
Using Eclipse project : /Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android
The directory 'android-16' can't be found in ANDROID_SDK_ROOT/platforms, please use --ap to set needed PI level

I cannot use such an old API level as android-16 in my project. So I use this command:

cocos run -p android -m release --ap android-22

Giving this error:

Building mode: release
Using Eclipse project : /Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android
running: '/Users/krow/Library/Android/sdk/tools/android update project -t android-22 -p /Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android'

*************************************************************************
The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
*************************************************************************
Invalid or unsupported command "update project -t android-22 -p /Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android"

Supported commands are:
android list target
android list avd
android list device
android create avd
android move avd
android delete avd
android list sdk
android update sdk
Error running command, return code: 2.

Also, the cpp directory only contains proj.android proj.ios_mac. There is no proj.android-studio.

go to https://developer.android.com/studio/index.html download tools.

Thanks, it goes further now but still fails:

$ cocos run -p android -m release --ap android-22
Building mode: release
Using Eclipse project : /Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android
running: '/Users/krow/Library/Android/sdk/tools/android update project -t android-22 -p /Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android'

Updated project.properties
Updated local.properties
Updated file /Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android/proguard-project.txt
running: '/Users/krow/Library/Android/sdk/tools/android update lib-project -p /Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android/libs/gps -t android-22'

Updated project.properties
Updated local.properties
Updated file /Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android/libs/gps/proguard-project.txt
Building native...
NDK build mode: release
running: '/Users/krow/Library/Android/sdk/ndk-bundle/ndk-build -C /Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android -j8 NDK_MODULE_PATH=/Users/krow/Desktop/sdkbox-cocos2d-x-binary:/Users/krow/Desktop/sdkbox-cocos2d-x-binary/cocos:/Users/krow/Desktop/sdkbox-cocos2d-x-binary/external NDK_TOOLCHAIN_VERSION=4.9'

Android NDK: ERROR:/Users/krow/Desktop/sdkbox-cocos2d-x-binary/cocos/./prebuilt-mk/Android.mk:cocos2dx_internal_static: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that /Users/krow/Desktop/sdkbox-cocos2d-x-binary/cocos/./prebuilt-mk/../../prebuilt/android/arm64-v8a/libcocos2dxinternal.a exists  or that its path is correct
make: Entering directory `/Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android'
/Users/krow/Library/Android/sdk/ndk-bundle/build/core/prebuilt-library.mk:45: *** Android NDK: Aborting    .  Stop.
make: Leaving directory `/Users/krow/Desktop/sdkbox-sample-iap/cpp/proj.android'
Error running command, return code: 2.

Checking the content of that directory:

$ cd /Users/krow/Desktop/sdkbox-cocos2d-x-binary/cocos/./prebuilt-mk/../../prebuilt/android/
$ ls
armeabi

Looks like something wrong with the Application.mk you don’t need arm64-v8a

Thanks, appended this line to proj.android/jni/Application.mk:

APP_ABI := armeabi

Now the build progresses further, but fails with:

/Users/krow/Library/Android/sdk/ndk-bundle/build/core/build-binary.mk:687: Android NDK: Module cocos2dcpp_shared depends on undefined modules: android_native_app_glue cocos_curl_static
/Users/krow/Library/Android/sdk/ndk-bundle/build/core/build-binary.mk:700: *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)    .  Stop.

android-ndk-r10d is ok, i’m trying https://dl.google.com/android/repository/android-ndk-r14-darwin-x86_64.zip

proj.android/jni/Application.mk:

APP_STL := gnustl_static
APP_ABI := armeabi
APP_ALLOW_MISSING_DEPS := true     # here

APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char
APP_LDFLAGS := -latomic


ifeq ($(NDK_DEBUG),1)
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
APP_OPTIM := debug
else
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
APP_OPTIM := release
endif
APP_PLATFORM := android-9

compile

I’m using 3.14.1’s cocos command

cocos compile -p android --app-abi armeabi

error

make: Entering directory `/Volumes/data/work/sdkbox/sdkbox-sample-iap/cpp/proj.android'
/Volumes/data/work/android-ndk-r14/build/core/build-binary.mk:687: Android NDK: Module cocos2dcpp_shared depends on undefined modules: android_native_app_glue cocos_curl_static
[armeabi] Compile++ thumb: cocos2dcpp_shared <= main.cpp
[armeabi] Compile++ thumb: cocos2dcpp_shared <= AppDelegate.cpp
[armeabi] Compile++ thumb: cocos2dcpp_shared <= HelloWorldScene.cpp
[armeabi] Compile thumb  : cpufeatures <= cpu-features.c
[armeabi] Gdbserver      : [arm-linux-androideabi-4.9] libs/armeabi/gdbserver
[armeabi] Gdbsetup       : libs/armeabi/gdb.setup
[armeabi] StaticLibrary  : libcpufeatures.a
jni/../../Classes/HelloWorldScene.cpp: In member function 'void HelloWorld::createTestMenu()':
jni/../../Classes/HelloWorldScene.cpp:82:33: warning: not enough variable arguments to fit a sentinel [-Wformat=]
     _iapMenu = Menu::create(NULL);
                                 ^
At global scope:
cc1plus: warning: unrecognized command line option "-Wno-extern-c-compat"
cc1plus: warning: unrecognized command line option "-Wno-extern-c-compat"


[armeabi] SharedLibrary  : libcocos2dcpp.so
/Volumes/data/work/sdkbox/sdkbox-cocos2d-x-binary/cocos/./prebuilt-mk/../../prebuilt/android/armeabi/libcocos2dxinternal.a(CCConsole.o):function cocos2d::Console::listenOnTCP(int): error: undefined reference to 'bzero'


/Volumes/data/work/sdkbox/sdkbox-cocos2d-x-binary/external/websockets/prebuilt/android/armeabi/libwebsockets.a(context.c.o):context.c:function libwebsocket_create_context: error: undefined reference to 'getdtablesize'
collect2: error: ld returned 1 exit status
make: *** [obj/local/armeabi/libcocos2dcpp.so] Error 1
make: Leaving directory `/Volumes/data/work/sdkbox/sdkbox-sample-iap/cpp/proj.android'

two issues:

undefined reference to 'bzero'
undefined reference to 'getdtablesize'

20:23 update

test cpp314.1, source project with facebook plugin and compile command:

cocos compile -p android --app-abi armeabi -j 8

proj.android/jni/Application.mk

/Volumes/data/work/cpp314 [master] $ cat proj.android/jni/Application.mk
APP_STL := gnustl_static #c++_static  #c++_static still compile error
APP_ALLOW_MISSING_DEPS := true

APP_CPPFLAGS := -frtti \
-DCC_ENABLE_CHIPMUNK_INTEGRATION=1 \
-std=c++11 \
-fsigned-char
APP_LDFLAGS := -latomic

APP_ABI := armeabi


ifeq ($(NDK_DEBUG),1)
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
APP_OPTIM := debug
else
APP_CPPFLAGS += -DNDEBUG
APP_OPTIM := release
endif
APP_PLATFORM := android-15

BUILD SUCCESSFUL

Thanks for your work on this.

APP_STL := gnustl_static #c++_static  #c++_static still compile error

Unfortunately the rest of my project won’t compile with gnustl_static, only c++_static.

Have you tried using ndk r10d or r10e?

Yes. A lot of code in my project builds no problem in the latest Visual Studio, XCode and NDK r14, but cannot build in NDK r10e. There are bugs in

<functional>

in r10e for example, that have been fixed in newer NDK versions.

Edit:

Looking at the NDK version history:

https://developer.android.com/ndk/downloads/revision_history.html

r10e is from May 2015. Starting with r11:

We strongly recommend switching to Clang

and

GCC in the NDK is now deprecated in favor of Clang

This makes cross platform development easier: we already have to use Clang for iOS/macOS, so we will only need to support 2 compilers: Microsoft Visual C++ and Clang. (Not GCC.)

cocos2d-x tried to switch to clang with 3.13 and it didn’t end well, there are still bugs with clang. Meanwhile we’re still looking into the r14 issue.

OK, thanks. Would it maybe help compatibility if we had a dynamically linked SDKBox for Android, i.e. libsdkbox.so instead of libsdkbox.a?

Yes it’s possible to have a dynamic lib, it would be actually easier to integrate.

1 Like

I’m using windows, cocos 3.15, Android Studio 2.3.2, targetSdkVersion 13.

After integrating iap the missing dependencies error persist.
Module MyGame_shared depends on undefined modules: android_native_app_glue

App compiles wirh APP_ALLOW_MISSING_DEPS := true in Android.mk but not sure if this is safe to use.

Can you try lower your NDK version to 10e maybe?

I’m not really willing to downgrade NDK because 13 is the current default for Cocos so i don’t know if this is safe. I’ll give it it a try and report but would prefer to maintain NDK 13, guess Cocos sets it to 13 for a reason.

Currently changed in Android.mk:

LOCAL_WHOLE_STATIC_LIBRARIES := PluginSdkboxPlay
sdkbox
PluginReview
PluginIAP
android_native_app_glue

To:

LOCAL_WHOLE_STATIC_LIBRARIES := PluginSdkboxPlay
sdkbox
PluginReview
PluginIAP

Seems to run fine, i can do purchases to google in the alpha version.

1 Like

Changed to NDK 10, setting PROP_TARGET_SDK_VERSION=10 in gradle.properties, cleared project to be safe but still getting the same gradle error.

Error:(686, 0) Android NDK: Module MyGame_shared depends on undefined modules: android_native_app_glue

I don’t think this will change NDK version, you need to download ndk here

new NDK version support is underway.

Hope you fix it soon, i’m using AdMob, also via SDKBox and min sdk version is 14.

Game is in beta and purchases seem to go fine with Google servers. Just removed android_native_app_glue from LOCAL_WHOLE_STATIC_LIBRARIES in Android.mk.

Hei,

Which STL you use, gnustl_static or c++_static ?