"&的UnsatisfiedLinkError QUOT;出现时" dynamic_cast的"在Android的NDK使用 [英] "UnsatisfiedLinkError" appears when "dynamic_cast" is used in Android NDK
问题描述
我在Android版开发新的和我面临着一个问题:
使用时,使用的的dynamic_cast前pressions C ++ code I - 的UnsatisfiedLinkError:当我开始我在模拟器上的应用程序显示。但是,当我没有它运行的应用程序 - 所有的工作确定(我的意思是没有任何错误LogCat中)
I am new in the developing for Android and I faced with next problem: when I using C++ code that uses "dynamic_cast" expressions - "UnsatisfiedLinkError" appears when I am starting my application on an emulator. But when I run application without it - all works OK( I mean without any errors to LogCat )
我试图在Android 2.3.3运行它。我用Android的NDK-R7B。
I tried to run it on Android 2.3.3. I used android-ndk-r7b.
我的Application.mk:
My Application.mk:
APP_OPTIM := debug
APP_ABI := armeabi
APP_STL := gnustl_static
APP_MODULES := native_lab
我的Android.mk:
My Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native_lab
LOCAL_SRC_FILES := native.cpp enum_if.cpp torrent.cpp
LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_LDLIBS := -llog -lz \
/home/l/android9_toolchain/arm-linux-androideabi/lib/libstdc++.a
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
include $(BUILD_SHARED_LIBRARY)
code的使用动态投片:
The pieces of code that uses dynamic cast:
namespace libtorrent
{
template <class T>
T* alert_cast(alert* a)
{
return dynamic_cast<T*>(a);
}
}
.....
using namespace libtorrent;
if (torrent_finished_alert* p = alert_cast<torrent_finished_alert>(a)){}
登录猫说:
03-27 07:28:26.465: D/dalvikvm(404): Trying to load lib /data/data/com.example/lib/libnative_lab.so 0x405149b8
03-27 07:28:26.496: W/dalvikvm(404): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/example/Bt2Activity;
03-27 07:28:26.555: W/dalvikvm(404): Class init failed in newInstance call (Lcom/example/Bt2Activity;)
03-27 07:28:26.555: D/AndroidRuntime(404): Shutting down VM
03-27 07:28:26.575: W/dalvikvm(404): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-27 07:28:26.615: E/AndroidRuntime(404): FATAL EXCEPTION: main
03-27 07:28:26.615: E/AndroidRuntime(404): java.lang.ExceptionInInitializerError
03-27 07:28:26.615: E/AndroidRuntime(404): at java.lang.Class.newInstanceImpl(Native Method)
难道有人知道如何解决这个问题?
Do anybody know how to solve this problem?
推荐答案
尝试包括这些行到你的Applications.mk:
Try to include these lines into your Applications.mk:
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions
你有Java中的任何方法标记为'本土'?
Do you have any methods in Java marked as 'native'?
这篇关于&QUOT;&的UnsatisfiedLinkError QUOT;出现时&QUOT; dynamic_cast的&QUOT;在Android的NDK使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!