How-to use a shared library in native-activity

转自:http://stackoverflow.com/questions/9111107/how-to-use-a-shared-library-in-native-activity

I have an Android project with a native activity.This native activity uses a shared library named "main" (libmain.so file) for starting.( with the code of ndk/samples/native-activity )

This app works fine.

the "main" module Android.mk file :

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

LOCAL_MODULE    := main
LOCAL_SRC_FILES := main.cpp

LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM

LOCAL_STATIC_LIBRARIES := android_native_app_glue game

include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)

Now I want to add another shared library (for example a game engine) used by "main" library.I have built a "game" module (libgame.so).

But when I link the "main" with the "game", like this :

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

LOCAL_MODULE    := main
LOCAL_SRC_FILES := main.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../game

LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM
LOCAL_LDLIBS += $(LOCAL_PATH)/../../libs/$(TARGET_ARCH_ABI)/libgame.so

LOCAL_STATIC_LIBRARIES := android_native_app_glue game

include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)

with code no changes !
the app doesn't start anymore and I have this error in Logcat :

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.myproject/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/data/com.mycompany.myproject/lib/libmain.so

This crash is due to adding link to a shared library ...

Why linking to a shared library make the app not loading (crash) ?
How can I use a shared library in a native android project (no-java / native-activity) ?
(I suppose it can be possible ... otherwise the native activity is quite limited ...)

Thanks ! :)


Answer

I believe you must list all your shared libraries in AndroidManifest.xml file:

<meta-data android:name="android.app.lib_name" android:value="game" />
<meta-data android:name="android.app.lib_name" android:value="main" />

Not sure about the order of libraries. Try change the order if it doesn't work.



Thanks ! But, are you sure ? Have you already tried this ? I have tried this and changing the order ... the problem is the same (crash)http://pastie.org/3308037


I am having the exact same issue as you. This did not fix it.


Yes, my answer was incorrect. This considered as a bug:code.google.com/p/android/issues/detail?id=28329 Simple workaround would be subclass NativeActivity with empty activity that has only System.loadLibrary() calls to load all needed libraries.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值