SDKBox integration for non-standard NDK setup

Having integrated FMOD into my project, I have a very non-standard setup for my NDK Makefiles and I have recently started trying to integrate Google Analytics.

Having tried the automatic setup from sdkbox-ui and commandline, the typical setup of adding

LOCAL_WHOLE_STATIC_LIBRARIES := PluginGoogleAnalytics
$(call import-module, ./plugingoogleanalytics)

does not work, it results in

Android NDK: jni/Android.mk: Cannot find module with tag ‘./plugingoogleanalytics’ in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?

I’ve tried endlessly to get this to work with my setup to no avail, trying to use

include jni/fmod/Android.mk

in my Android.mk or adding LOCAL_WHOLE_STATIC_LIBRARIES into my specific cocos2dx module…


Could someone possibly give some advice how to setup SDKBOX with my configuration? I understand NDK to a fairly basic level (outside of managing to add FMOD compilation) and SDKBOX doesn’t really provide any guidance outside the automatic installer.

My setup has two Android.mk files in subdirectories (fmod & main), for fmod and for cocos2dx (standard cocos2dx makefile), both of which are included from a top-level Android.mk

/jni
-> /fmod
-> /main
-> /plugingoogleanalytics

Top-level /jni/Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

include jni/fmod/Android.mk
include jni/main/Android.mk

and my Android.mk for cocos2dx (main) looks like such

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)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_SHARED_LIBRARIES := fmod \
                            fmodProvider

LOCAL_MODULE_FILENAME := libcocos2dcpp

LOCAL_CFLAGS += -std=c++11
APP_USE_CPP0X := true
NDK_TOOLCHAIN_VERSION := 4.7

PCH_FILE := $(LOCAL_PATH)/header.h
LOCAL_CPPFLAGS += -include $(PCH_FILE)

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../../Classes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../fmod/
FILE_LIST := $(wildcard $(LOCAL_PATH)/../../../../Classes/*.cpp) \
                   $(wildcard $(LOCAL_PATH)/../../../../Classes/*.c)
LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%) \
                    main.cpp \
                    PurchaseManagerAndroid.cpp \

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END


LOCAL_STATIC_LIBRARIES := cocos2dx_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

$(call import-module,.)

# _COCOS_LIB_IMPORT_ANDROID_BEGIN

I have already previously given up on this and decided to make my own implementation and NDK bridging for in-app purchases having faced this issue for inapp purchases too, however I’d really love to get analytics working as it is a lot more involved to bridge across by hand…

Can you post a screenshot of the folder structure of your jni folder?

Sounds to me you just to need to point to the correct path so it can find plugingoogleanalytics. What’s your folder structure looks like?

Is it like this?

sdkbox
plugingoogleanalytics
main
fmod

That’s right, the structure looks as follows:

Should I supposedly only need to add the following?

LOCAL_WHOLE_STATIC_LIBRARIES := PluginGoogleAnalytics
$(call import-module, ./plugingoogleanalytics)

If so, should this be at the top-level Android.mk or the main/cocos2dx one? And if so, where in the file? I’ve tried permutations of this to no avail before (including modifying the import path to ‘…/plugingoogleanalytics’

Try the following

Also print out the LOCAL_PATH so you can make adjustments based on the output

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

# Print out LOCAL_PATH to make sure path is correct
$(warning $(LOCAL_PATH))

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

This seems to be a step in the right direction actually, everything builds now but I can’t seem to import the headers in shared cocos2dx code.

I’ve changed it to this:

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)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_SHARED_LIBRARIES := fmod \
                            fmodProvider

LOCAL_MODULE_FILENAME := libcocos2dcpp

LOCAL_CFLAGS += -std=c++11
APP_USE_CPP0X := true
NDK_TOOLCHAIN_VERSION := 4.7

PCH_FILE := $(LOCAL_PATH)/header.h
LOCAL_CPPFLAGS += -include $(PCH_FILE)

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../../Classes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../fmod/
FILE_LIST := $(wildcard $(LOCAL_PATH)/../../../../Classes/*.cpp) \
                   $(wildcard $(LOCAL_PATH)/../../../../Classes/*.c)
LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%) \
                    main.cpp \
                    PurchaseManagerAndroid.cpp \

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END


LOCAL_STATIC_LIBRARIES := cocos2dx_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

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

# Print out LOCAL_PATH to make sure path is correct
$(warning $(LOCAL_PATH))

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



# _COCOS_LIB_IMPORT_ANDROID_BEGIN

But when importing

#include “PluginGoogleAnalytics/PluginGoogleAnalytics.h”

I get

jni/main/…/…/…/…/Classes/AppDelegate.cpp:14:57: fatal error: PluginGoogleAnalytics/PluginGoogleAnalytics.h: No such file or directory
compilation terminated.

I think I’ve gotten to this stage before and tried manually including headers from …/plugingoogleanalytics but ended up with unreferenced vtables.

Add this to include path

Definitely a step in the right direction!
Passing the include now but getting

jni/main/…/…/…/…/Classes/AppDelegate.cpp:69: error: undefined reference to ‘sdkbox::PluginGoogleAnalytics::init(char const*)’
collect2: error: ld returned 1 exit status

for the init() call…

I finally got the build to work!

I realised I was missing

LOCAL_WHOLE_STATIC_LIBRARIES := PluginGoogleAnalytics

because I hadn’t re-added it since asking for help and everything seems to be building fine now?
I had a little NDK trouble on the way as sdkbox wasn’t building with Crystax NDK, but switching back to NDK 9 seemed to resolve the issues

For the record and anyone that googles across this thread (I read every single related sdkbox one for things to try before asking) my full Android.mk is as such:

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)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_SHARED_LIBRARIES := fmod \
                            fmodProvider

LOCAL_MODULE_FILENAME := libcocos2dcpp

LOCAL_CFLAGS += -std=c++11
APP_USE_CPP0X := true
NDK_TOOLCHAIN_VERSION := 4.7

PCH_FILE := $(LOCAL_PATH)/header.h
LOCAL_CPPFLAGS += -include $(PCH_FILE)

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../../Classes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../fmod/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/..

FILE_LIST := $(wildcard $(LOCAL_PATH)/../../../../Classes/*.cpp) \
                   $(wildcard $(LOCAL_PATH)/../../../../Classes/*.c)
LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%) \
                    main.cpp \
                    PurchaseManagerAndroid.cpp \

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END


LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += PluginGoogleAnalytics

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

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

# Print out LOCAL_PATH to make sure path is correct
$(warning $(LOCAL_PATH))

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

# _COCOS_LIB_IMPORT_ANDROID_BEGIN

Following this, I had issues with re-definition of IInappBillingService in multiple dex files when trying to build the app which I realized was from my own separate implementation of inapp purchases importing the billing aidl.

Now that the analytics module was building though, I tore out my own implementation and hot-swapped it for the sdkbox one which is also now working and running! (thank god for modular design from my end up-front!)

Thanks so much for the help, I really needed the guidance in the buildfile to reduce some of the factors left with things not working (NDK, dex, etc). (´・ω・`)

1 Like