可能重复:
纯粹从本机代码加载 FMOD
我正在尝试在 android ndk 项目上链接 fmod 库,但我遇到了致命的异常错误。
我的 android.mk 看起来像这样:
LOCAL_PATH := $(call my-dir)
#FMOD Ex Shared Library#########
include $(CLEAR_VARS)
LOCAL_MODULE := fmodex
LOCAL_SRC_FILES := libfmodex.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/fmod
include $(PREBUILT_SHARED_LIBRARY)
#lua############################
include $(CLEAR_VARS)
LOCAL_MODULE := lua
FILE_LIST := $(wildcard $(LOCAL_PATH)/lua/*.c)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_STATIC_LIBRARY)
#libpng########################
include $(CLEAR_VARS)
LOCAL_CFLAGS :=
LOCAL_MODULE := libpng
FILE_LIST := $(wildcard $(LOCAL_PATH)/libpng/*.c)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_STATIC_LIBRARY)
#ghost##########################
include $(CLEAR_VARS)
LOCAL_MODULE := ghost
FILE_LIST := $(wildcard $(LOCAL_PATH)/ghost/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 -L$(SYSROOT)/usr/lib -ldl -L$(SYSROOT)/usr/lib -lz
# Enable debugging.
APP_OPTIM := debug
# Support for additional libraries
#LOCAL_CFLAGS := -DANDROID_NDK -Wno-psabi
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libpng/ $(LOCAL_PATH)/lua/
LOCAL_SHARED_LIBRARIES := fmodex
LOCAL_STATIC_LIBRARIES := libpng android_native_app_glue lua
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
ndk-build 命令成功,没有任何错误,但是当我编译时,出现以下错误:
10-15 14:25:49.220: E/AndroidRuntime(16255): FATAL EXCEPTION: main
10-15 14:25:49.220: E/AndroidRuntime(16255): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.native_activity/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/data/com.example.native_activity/lib/libghost.so
10-15 14:25:49.220: E/AndroidRuntime(16255): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
10-15 14:25:49.220: E/AndroidRuntime(16255): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
10-15 14:25:49.220: E/AndroidRuntime(16255): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
10-15 14:25:49.220: E/AndroidRuntime(16255): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
10-15 14:25:49.220: E/AndroidRuntime(16255): at android.os.Handler.dispatchMessage(Handler.java:99)
10-15 14:25:49.220: E/AndroidRuntime(16255): at android.os.Looper.loop(Looper.java:130)
10-15 14:25:49.220: E/AndroidRuntime(16255): at android.app.ActivityThread.main(ActivityThread.java:3701)
10-15 14:25:49.220: E/AndroidRuntime(16255): at java.lang.reflect.Method.invokeNative(Native Method)
10-15 14:25:49.220: E/AndroidRuntime(16255): at java.lang.reflect.Method.invoke(Method.java:507)
10-15 14:25:49.220: E/AndroidRuntime(16255): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
10-15 14:25:49.220: E/AndroidRuntime(16255): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
10-15 14:25:49.220: E/AndroidRuntime(16255): at dalvik.system.NativeStart.main(Native Method)
10-15 14:25:49.220: E/AndroidRuntime(16255): Caused by: java.lang.IllegalArgumentException: Unable to load native library: /data/data/com.example.native_activity/lib/libghost.so
10-15 14:25:49.220: E/AndroidRuntime(16255): at android.app.NativeActivity.onCreate(NativeActivity.java:199)
10-15 14:25:49.220: E/AndroidRuntime(16255): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-15 14:25:49.220: E/AndroidRuntime(16255): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
10-15 14:25:49.220: E/AndroidRuntime(16255): ... 11 more
如果我删除以下行,代码将在没有 fmod 支持的情况下正常编译和运行。
include $(CLEAR_VARS)
LOCAL_MODULE := fmodex
LOCAL_SRC_FILES := libfmodex.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/fmod
include $(PREBUILT_SHARED_LIBRARY)
和
LOCAL_SHARED_LIBRARIES := fmodex
我尝试使用 fmod 示例编译本机活动,令我惊讶的是它起作用了。我什至将我的文件位置调整为示例,但没有帮助。
任何帮助,将不胜感激。