在Android NDK中使用“dynamic_cast”时会出现“UnsatisfiedLinkError”
作者:互联网
我是Android的新手,我遇到了下一个问题:
当我使用使用“dynamic_cast”表达式的C代码时 – 当我在模拟器上启动应用程序时出现“UnsatisfiedLinkError”.但是当我没有它运行应用程序时 – 一切正常(我的意思是没有任何错误到LogCat)
我试图在Android 2.3.3上运行它.我用的是android-ndk-r7b.
我的Application.mk:
APP_OPTIM := debug
APP_ABI := armeabi
APP_STL := gnustl_static
APP_MODULES := native_lab
我的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)
使用动态强制转换的代码片段:
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)){}
Log cat说:
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)
有谁知道如何解决这个问题?
解决方法:
尝试将这些行包含到您的Applications.mk中:
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions
你有任何Java标记为’本机’的方法吗?
标签:c-2,android,dynamic,android-ndk,dynamic-cast 来源: https://codeday.me/bug/20190613/1233774.html