# FMOD Studio, Cocos2d-x 3.10, Android

**URL:** <https://qa.fmod.com/t/fmod-studio-cocos2d-x-3-10-android/12305>\
**Category:** FMOD Engine\
**Created:** [February 12, 2016, 5:25am UTC](https://qa.fmod.com/t/fmod-studio-cocos2d-x-3-10-android/12305 "2016-02-12T05:25:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nvowell](https://avatars.discourse-cdn.com/v4/letter/n/e19b73/32.png) [@nvowell](https://qa.fmod.com/u/nvowell)\
**Post date:** [February 12, 2016, 5:25am UTC](https://qa.fmod.com/t/fmod-studio-cocos2d-x-3-10-android/12305/1 "2016-02-12T05:25:58Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mathew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mathew/32/431_2.png) [@mathew](https://qa.fmod.com/u/mathew)\
**Post date:** [February 14, 2016, 9:13pm UTC](https://qa.fmod.com/t/fmod-studio-cocos2d-x-3-10-android/12305/2 "2016-02-14T21:13:20Z")

</div>

> [@](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![nvowell](https://avatars.discourse-cdn.com/v4/letter/n/e19b73/32.png) [@nvowell](https://qa.fmod.com/u/nvowell)\
**Post date:** [February 15, 2016, 10:13am UTC](https://qa.fmod.com/t/fmod-studio-cocos2d-x-3-10-android/12305/3 "2016-02-15T10:13:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mathew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mathew/32/431_2.png) [@mathew](https://qa.fmod.com/u/mathew)\
**Post date:** [February 15, 2016, 8:44pm UTC](https://qa.fmod.com/t/fmod-studio-cocos2d-x-3-10-android/12305/4 "2016-02-15T20:44:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stirem](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@stirem](https://qa.fmod.com/u/stirem)\
**Post date:** [February 16, 2017, 10:14am UTC](https://qa.fmod.com/t/fmod-studio-cocos2d-x-3-10-android/12305/5 "2017-02-16T10:14:13Z")

</div>

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)
```

---

<div class="post-metadata">

**Author:** ![stirem](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@stirem](https://qa.fmod.com/u/stirem)\
**Post date:** [February 16, 2017, 10:32am UTC](https://qa.fmod.com/t/fmod-studio-cocos2d-x-3-10-android/12305/6 "2017-02-16T10:32:40Z")

</div>

> [@](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![stirem](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@stirem](https://qa.fmod.com/u/stirem)\
**Post date:** [February 16, 2017, 2:16pm UTC](https://qa.fmod.com/t/fmod-studio-cocos2d-x-3-10-android/12305/7 "2017-02-16T14:16:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stirem](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@stirem](https://qa.fmod.com/u/stirem)\
**Post date:** [February 24, 2017, 1:53pm UTC](https://qa.fmod.com/t/fmod-studio-cocos2d-x-3-10-android/12305/8 "2017-02-24T13:53:35Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![qdcmsll](https://avatars.discourse-cdn.com/v4/letter/q/bc8723/32.png) [@qdcmsll](https://qa.fmod.com/u/qdcmsll)\
**Post date:** [March 10, 2017, 8:22am UTC](https://qa.fmod.com/t/fmod-studio-cocos2d-x-3-10-android/12305/9 "2017-03-10T08:22:16Z")

</div>

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
