FMOD Studio, Cocos2d-x 3.10, Android

Hi everyone,

I am working on integrating FMOD Studio with my Cocos2dx cross-platform game (iOS and Android). Everything works perfectly in iOS, but in the Android project I’m running into some problems.

I’ve edited the jni/Android.mk file to find the fmod .so files (this took a while to figure out) and it compiles fine using the cocos compile command. However, when I run the project using Android Studio I get a runtime error “Fatal Signal 11” at the line system->initialize.

I searched for solutions and found that it may have something to do with the fmod.jar file, but I can’t figure out how to include this file in the project. Does Cocos2d-x have any .java files, .mk files, or other configuration files that need to be edited to connect this file to the project?

Has anyone gotten FMOD to work with Cocos2d-x on Android before? If so, what am I missing? There doesn’t seem to be much information available.

Thanks!

Can you try linking with the logging version of FMOD? This should give some information about what is going wrong in LogCat.

You are correct about the fmod.jar, it is required. I would recommend consulting the Cocos documentation on how to add Java dependencies to the project.

1 Like

Thanks, that pointed me in the right direction and I was able to get it working. The missing fmod.jar file was causing the runtime error.

The solution was to include the missing fmod.jar file in the project.

FMOD uses many Java only APIs to operate, it does so by calling from native code out to Java via JNI. If the fmod.jar file isn’t present we are unable to call these necessary Java only APIs.

Hi!
I think I have the same problem as described here. But I can’t find a way to properly add the fmod.jar to the project. Here is my android.mk file, which seems to ignore the fmod.jar inclusion:

LOCAL_PATH := $(call my-dir)

LOCAL_STATIC_JAVA_LIBRARIES := fmodJar
include $(CLEAR_VARS)
include $(BUILD_PACKAGE)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := fmodJar:../../../fmodLib/android/fmod.jar
include $(BUILD_MULTI_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := libfmodL
LOCAL_SRC_FILES := ../../../fmodLib/android/debug/libfmodL.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libfmodstudioL
LOCAL_SRC_FILES := ../../../fmodLib/android/debug/libfmodstudioL.so
include $(PREBUILT_SHARED_LIBRARY)

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_MODULE_FILENAME := libcocos2dcpp

LOCAL_SRC_FILES := hellocpp/main.cpp \
               ../../../Classes/AppDelegate.cpp \
               ../../../Classes/HelloWorldScene.cpp \
               ../../../Classes/FMODAudioEngine_android.cpp \

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes \
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../fmodClasses/inc_android/lowlevel \
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../fmodClasses/inc_android/studio \

LOCAL_STATIC_LIBRARIES := cocos2dx_static 

LOCAL_SHARED_LIBRARIES := libfmodstudioL
LOCAL_SHARED_LIBRARIES += libfmodL

include $(BUILD_SHARED_LIBRARY)

$(call import-module,.)

I get this error in Android Studio:

02-16 11:10:43.391 26858-26886/com.mycompany.myapp E/fmod: FMOD_JNI_GetEnv                          
: JNI_OnLoad has not run, should have occurred during System.LoadLibrary.
02-16 11:10:43.401 26858-26886/com.mycompany.myapp E/fmod: FMOD_JNI_GetEnv : 
JNI_OnLoad has not run, should have occurred during System.LoadLibrary.

02-16 11:10:43.401 26858-26886/com.mycompany.myapp A/libc: 
jni/../../../Classes/FMODAudioEngine_android.cpp:34: 
FMOD::Studio::System* FMODAudioEngine::getStudioSystem(): assertion "result == FMOD_OK" failed
02-16 11:10:43.401 26858-26886/com.mycompany.myapp A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 26886 (GLThread 9359)

This is the command I use in Terminal to build: cocos compile --android-studio --target android-22 --ap android-22 --ndk-mode debug --ndk-toolchain arm-linux-androideabi-4.9 --platform android --app-abi armeabi

I guess I have to add the fmod.jar file to the Android Studio project, not in Android.mk. I have it in proj.android-studio/app/libs folder. Right-clicked the file and selected “Add as library”. In “build.gradle” (Module: MyProject) its listed under dependencies: compile files(‘libs/fmod.jar’). Still same “Fatal signal 6” error.

I managed to build Cocos2d-x with FMOD on Android. Here is what I did:

1. cocos2d-x setup.py: add "/" at end of each NDK and ANT directory

2. Copy fmod classes to project dir (eg. projectDir/fmodClasses/inc_android )

3. Add ALL cpp and library files to Android:
- edit /proj.android-studio/app/jni/Android.mk


------------------------------Android.mk-----------------------------------
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libfmodL
LOCAL_SRC_FILES := ../../../fmodLib/android/debug/libfmodL.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libfmod
LOCAL_SRC_FILES := ../../../fmodLib/android/release/libfmod.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libfmodstudioL
LOCAL_SRC_FILES := ../../../fmodLib/android/debug/libfmodstudioL.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libfmodstudio
LOCAL_SRC_FILES := ../../../fmodLib/android/release/libfmodstudio.so
include $(PREBUILT_SHARED_LIBRARY)

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_MODULE_FILENAME := libcocos2dcpp

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../../Classes/AppDelegate.cpp \
                   ../../../Classes/HelloWorldScene.cpp \
                   ../../../Classes/FMODAudioEngine_android.cpp \

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes \
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../fmodClasses/inc_android/lowlevel \
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../fmodClasses/inc_android/studio \


# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END

LOCAL_STATIC_LIBRARIES := cocos2dx_static 

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

LOCAL_SHARED_LIBRARIES := libfmodstudioL
LOCAL_SHARED_LIBRARIES += libfmodL
LOCAL_SHARED_LIBRARIES += libfmodstudio
LOCAL_SHARED_LIBRARIES += libfmod

include $(BUILD_SHARED_LIBRARY)

$(call import-module,.)

# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END
----------------------------------------------------------------------------



4. Install Java Development Kit (jdk)

5. Edit file: /AppName/cocos2d/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java
	- under: protected void onLoadNativeLibraries() after System.loadLibrary(libName)
            System.loadLibrary("fmodL");
            System.loadLibrary("fmodstudioL");
            System.loadLibrary("fmod");
            System.loadLibrary("fmodstudio");
    - under: protected void onCreate(final Bundle savedInstanceState) at the end
            	org.fmod.FMOD.init(this);
    - under: protected void onDestroy() before super.onDestroy();
    			org.fmod.FMOD.close();


6. Include fmod.jar in Android Studio
	- Drag fmod.jar to libcocos2dx/src in Android Studio
	(path: /AppName/cocos2d/cocos/platform/android/java/src/fmod.jar)
  - Right-click fmod.jar and select "Add to library" select libcocos2dx in popup-box.


7. Copy MasterBank.bank and MasterBank.strings.bank to proj.android-studio/app/assets or build 
    to Resource dir in FMOD Studio. Then #define FILE_PREFIX "file:///android_asset/Mobile/" FMODAudioEngine_android.cpp


8. Teminal command to build: 
cocos compile --android-studio --target android-22 --ap android-22 --ndk-mode debug
--ndk-toolchain arm-linux-androideabi-4.9 --platform android --app-abi armeabi

I was working on integrating FMOD Studio with my Cocos2dx cross-platform game (iOS,win32 and Android),6 moths ago. Everything works perfectly in iOS and win32, but in the Android project I’m linking into some problems,today.The file type of ‘.ogg’ is supported by android,so I didn’t add fmod in android project. But,now ,I want to use fmod in android project,what should I do?I managed to build Cocos2d-x with FMOD on Android. Here is what I did:
LOCAL_PATH := $(call my-dir)

— 引用 libBugly.so —

include $(CLEAR_VARS)

LOCAL_MODULE := bugly_native_prebuilt

可在Application.mk添加APP_ABI := armeabi armeabi-v7a 指定集成对应架构的.so文件

LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/libBugly.so

include $(PREBUILT_SHARED_LIBRARY)

— end —

include $(CLEAR_VARS)
LOCAL_MODULE := fmod_native_prebuilt
LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/libfmod.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := fmodL_native_prebuilt
LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/libfmodL.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := cocos2dlua_shared
LOCAL_CFLAGS += -DCOCOS2D_DEBUG=1

LOCAL_MODULE_FILENAME := libcocos2dlua
LOCAL_SRC_FILES :=
…/…/Classes/AppDelegate.cpp
…/…/Classes/ide-support/SimpleConfigParser.cpp
…/…/Classes/ide-support/RuntimeLuaImpl.cpp
…/…/Classes/ide-support/lua_debugger.c
…/…/Classes/lua-modules/md5/md5.cpp
…/…/Classes/lua-modules/md5/lua_md5.cpp
…/…/Classes/network/ODSocket.cpp
…/…/Classes/network/SocketClient.cpp
…/…/Classes/lua-modules/DataMgr/GameDataManager.cpp
…/…/Classes/lua-modules/DataMgr/lua_DataMgr_c.cpp
…/…/Classes/lua-modules/devinfo/DeviceInfo.android.cpp
…/…/Classes/lua-modules/devinfo/devinfo.cpp
…/…/Classes/lua-modules/file.cpp
…/…/Classes/lua-modules/pack2lua/Protocal.cpp
…/…/Classes/lua-modules/pack2lua/lua_Protocal_c.cpp
…/…/Classes/lua-modules/TouchID/lua_touchid.cpp
…/…/Classes/lua-modules/TouchID/TouchID.cpp
…/…/Classes/lua-modules/http/lua_http.cpp
…/…/Classes/lua-modules/EventCenter/EventCenter.cpp
…/…/Classes/lua-modules/lua_modules.cpp
…/…/Classes/lua-modules/pack2lua/CodeConvert.cpp
…/…/Classes/lua-modules/lpeg/lpcap.c
…/…/Classes/lua-modules/lpeg/lpcode.c
…/…/Classes/lua-modules/lpeg/lpprint.c
…/…/Classes/lua-modules/lpeg/lptree.c
…/…/Classes/lua-modules/lpeg/lpvm.c
…/…/Classes/lua-modules/pbc/binding/lua/pbc-lua.c
…/…/Classes/lua-modules/qjson/json.cpp
…/…/Classes/lua-modules/qjson/lua_json.cpp
…/…/Classes/lua-modules/bugly/BuglyLuaAgent.cpp
…/…/Classes/lua-modules/bugly/CrashReport.cpp
…/…/Classes/lua-modules/cjson/fpconv.c
…/…/Classes/lua-modules/cjson/lua_cjson.c
…/…/Classes/lua-modules/cjson/strbuf.c
…/…/Classes/lua-modules/fmodplayer/FmodPlayer.cpp
…/…/Classes/lua-modules/fmodplayer/lua_FmodPlayer.cpp
hellolua/main.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/…/…/Classes
$(LOCAL_PATH)/…/…/…/cocos2d-x/cocos/platform/android/jni
$(LOCAL_PATH)/…/…/Classes/network
$(LOCAL_PATH)/…/…/Classes/network/uuid
$(LOCAL_PATH)/…/…/Classes/lua-modules/md5
$(LOCAL_PATH)/…/…/Classes/lua-modules/DataMgr
$(LOCAL_PATH)/…/…/Classes/lua-modules/devinfo
$(LOCAL_PATH)/…/…/Classes/lua-modules
$(LOCAL_PATH)/…/…/Classes/lua-modules/pack2lua
$(LOCAL_PATH)/…/…/Classes/lua-modules/TouchID
$(LOCAL_PATH)/…/…/Classes/lua-modules/http
$(LOCAL_PATH)/…/…/Classes/lua-modules/EventCenter
$(LOCAL_PATH)/…/…/Classes/lua-modules/lpeg
$(LOCAL_PATH)/…/…/Classes/lua-modules/pbc
$(LOCAL_PATH)/…/…/Classes/lua-modules/qjson
$(LOCAL_PATH)/…/…/Classes/lua-modules/bugly
$(LOCAL_PATH)/…/…/Classes/lua-modules/cjson
$(LOCAL_PATH)/…/…/Classes/lua-modules/fmodplayer/FmodLib/inc
$(LOCAL_PATH)/…/…/Classes/lua-modules/fmodplayer

_COCOS_HEADER_ANDROID_BEGIN

_COCOS_HEADER_ANDROID_END

LOCAL_STATIC_LIBRARIES := cocos2d_lua_static
LOCAL_STATIC_LIBRARIES += cocos2dxandroid_static

LOCAL_WHOLE_STATIC_LIBRARIES += pbc_static

_COCOS_LIB_ANDROID_BEGIN

_COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

$(call import-module,scripting/lua-bindings/proj.android)
$(call import-module,platform/android)
$(call import-module,pbc)

_COCOS_LIB_IMPORT_ANDROID_BEGIN

_COCOS_LIB_IMPORT_ANDROID_END