- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
注意 这个问题现在已经解决了 - 请看下面我的回答 - 除非有人删除这篇文章,否则它会留在这里只是为了记录我自己的愚蠢,我想......仍然,使 C++ 异常在 Android JNI 代码中工作的所有步骤和配置在下面都是正确的,所以也许它偶尔会对某人有所帮助 - Greg
我正在阅读有关此事的所有可能 Material ,但无法在静态构建的 native 库中使我的 C++ 异常正常工作……知道我遗漏了什么吗?
Application.mk,正如您在下面看到的,我尝试了 gnuSTL_static 和 STLport_static,但没有任何效果。我什至强行重建了 STLport_static ...
NDK_TOOLCHAIN_VERSION= 4.9
APP_PLATFORM := android-10
#APP_STL := gnustl_static
APP_STL := stlport_static
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -frtti
# STLPORT_FORCE_REBUILD := true
ifeq ($(NDK_DEBUG),1)
APP_OPTIM := debug
APP_ABI := x86
else
APP_OPTIM := release
APP_ABI := mips armeabi armeabi-v7a x86
endif
我正在尝试的代码:
//-----------------------------------------------------------------------
// Generic external error exception
struct ExternalException : public std::exception
{
public:
explicit ExternalException(const std::string &what)
: message(what) {}
virtual ~ExternalException() throw() {}
const char *what() const throw() { return message.c_str(); }
protected:
const std::string message;
};
然后在别处:
try
{
ret = SomeFunction();
}
catch (...)
{
ret = -1;
}
我也试过上面的 catch (ExternalException& e) {...}
,也没有帮助。
SomeFunction() 在特定错误条件下调用:
throw ExternalException(what);
然后应用程序就崩溃了。当我分析堆栈跟踪时,我发现异常 Unwind...() 调用什么都不做,然后它进入终止函数。
我想用头撞墙……这是怎么回事???
仅供快速引用,以下是我的本地编译器选项:
LOCAL_CFLAGS += -Wno-write-strings -gdwarf-2
LOCAL_CFLAGS += -ffunction-sections -fdata-sections -fvisibility=hidden
LOCAL_CPPFLAGS += -ffunction-sections -fdata-sections -fvisibility=hidden
更新
这是捕获的堆栈跟踪的一部分,这是在 Nexus 6P 设备上构建的 armeabi-v7a。之前我在 x86 模拟器上测试调试构建,完全相同的问题。接下来将尝试使用不同的 C/CPP 标志进行测试,也许那里有冲突?
********** Crash dump: **********
Build fingerprint: 'google/angler/angler:6.0.1/MMB29P/2473553:user/release-keys'
pid: 12307, tid: 12352, name: AsyncTask #4 >>> com.hyperionics.avar <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Stack frame #00 pc 00042374 /system/lib/libc.so (tgkill+12)
Stack frame #01 pc 0003ff81 /system/lib/libc.so (pthread_kill+32)
Stack frame #02 pc 0001c73f /system/lib/libc.so (raise+10)
Stack frame #03 pc 000198f1 /system/lib/libc.so (__libc_android_abort+34)
Stack frame #04 pc 000174b0 /system/lib/libc.so (abort+4)
Stack frame #05 pc 002ac143 /data/app/com.hyperionics.avar-1/lib/arm/libHyperionics_avar.so: Routine __gabixx::__default_terminate() at /tmp/ndk-user/tmp/build-stlport/ndk/sources/cxx-stl/gabi++/src/terminate.cc:75
Stack frame #06 pc 002ac14d /data/app/com.hyperionics.avar-1/lib/arm/libHyperionics_avar.so: Routine __gabixx::__terminate(void (*)()) at /tmp/ndk-user/tmp/build-stlport/ndk/sources/cxx-stl/gabi++/src/terminate.cc:84
Stack frame #07 pc 002ac1a5 /data/app/com.hyperionics.avar-1/lib/arm/libHyperionics_avar.so: Routine std::terminate() at /tmp/ndk-user/tmp/build-stlport/ndk/sources/cxx-stl/gabi++/src/terminate.cc:110
Stack frame #08 pc 002ab80f /data/app/com.hyperionics.avar-1/lib/arm/libHyperionics_avar.so: Routine __cxxabiv1::call_terminate(_Unwind_Control_Block*) at /tmp/ndk-user/tmp/build-stlport/ndk/sources/cxx-stl/gabi++/src/helper_func_internal.cc:54
Stack frame #09 pc 002ab21d /data/app/com.hyperionics.avar-1/lib/arm/libHyperionics_avar.so: Routine throwException at /tmp/ndk-user/tmp/build-stlport/ndk/sources/cxx-stl/gabi++/src/cxxabi.cc:271
Stack frame #10 pc 002ab2e1 /data/app/com.hyperionics.avar-1/lib/arm/libHyperionics_avar.so: Routine __cxa_throw at /tmp/ndk-user/tmp/build-stlport/ndk/sources/cxx-stl/gabi++/src/cxxabi.cc:335
Stack frame #11 pc 00045e58 /data/app/com.hyperionics.avar-1/lib/arm/libHyperionics_avar.so: Routine IOError(std::string const&, std::string const&) at C:\android\TtsNativeLib/jni/mylib/error.h:128 (discriminator 4)
格雷格
最佳答案
抱歉,一切正常。这是我的编程错误,显然我在晚上工作时状态不佳。
简而言之,问题是什么:在我对 SomeFunction() 的调用中,我实际上有参数,异常是在创建这些参数时,而不是在函数内部。只是我的“try {”指令必须向上移动......就像:
Ptr<OutPackedStream> pout = CreatePackedStream(fname.c_str());
try
{
ret = SomeFunction(pout);
}
catch (...)
{
ret = -1;
}
很明显,我无法在 CreatePackedStream() 中捕获异常,因为它不在 try{} 中...不过让我感到困惑的是堆栈跟踪指向 ret = SomeFunction(pout)
行,然后才转到 CreatePackedStream()
。现在看看代码,还有我的堆栈跟踪,这很明显,再次为我的笨拙道歉!
格雷格
关于android - Android JNI 代码中的 C++ 异常 - 再次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34757133/
我最近在/ drawable中添加了一些.gifs,以便可以将它们与按钮一起使用。这个工作正常(没有错误)。现在,当我重建/运行我的应用程序时,出现以下错误: Error: Gradle: Execu
Android 中有返回内部存储数据路径的方法吗? 我有 2 部 Android 智能手机(Samsung s2 和 s7 edge),我在其中安装了一个应用程序。我想使用位于这条路径中的 sqlit
这个问题在这里已经有了答案: What's the difference between "?android:" and "@android:" in an android layout xml f
我只想知道 android 开发手机、android 普通手机和 android root 手机之间的实际区别。 我们不能从实体店或除 android marketplace 以外的其他地方购买开发手
自Gradle更新以来,我正在努力使这个项目达到标准。这是一个团队项目,它使用的是android-apt插件。我已经进行了必要的语法更改(编译->实现和apt->注释处理器),但是编译器仍在告诉我存在
我是android和kotlin的新手,所以请原谅要解决的一个非常简单的问题! 我已经使用导航体系结构组件创建了一个基本应用程序,使用了底部的导航栏和三个导航选项。每个导航选项都指向一个专用片段,该片
我目前正在使用 Facebook official SDK for Android . 我现在正在使用高级示例应用程序,但我不知道如何让它获取应用程序墙/流/状态而不是登录的用户。 这可能吗?在那种情
我在下载文件时遇到问题, 我可以在模拟器中下载文件,但无法在手机上使用。我已经定义了上网和写入 SD 卡的权限。 我在服务器上有一个 doc 文件,如果用户单击下载。它下载文件。这在模拟器中工作正常但
这个问题在这里已经有了答案: What is the difference between gravity and layout_gravity in Android? (22 个答案) 关闭 9
任何人都可以告诉我什么是 android 缓存和应用程序缓存,因为当我们谈论缓存清理应用程序时,它的作用是,缓存清理概念是清理应用程序缓存还是像内存管理一样主存储、RAM、缓存是不同的并且据我所知,缓
假设应用程序 Foo 和 Eggs 在同一台 Android 设备上。任一应用程序都可以获取设备上所有应用程序的列表。一个应用程序是否有可能知道另一个应用程序是否已经运行以及运行了多长时间? 最佳答案
我有点困惑,我只看到了从 android 到 pc 或者从 android 到 pc 的例子。我需要制作一个从两部手机 (android) 连接的 android 应用程序进行视频聊天。我在想,我知道
用于使用 Android 以编程方式锁定屏幕。我从 Stackoverflow 之前关于此的问题中得到了一些好主意,并且我做得很好,但是当我运行该代码时,没有异常和错误。而且,屏幕没有锁定。请在这段代
文档说: android:layout_alignParentStart If true, makes the start edge of this view match the start edge
我不知道这两个属性和高度之间的区别。 以一个TextView为例,如果我将它的layout_width设置为wrap_content,并将它的width设置为50 dip,会发生什么情况? 最佳答案
这两个属性有什么关系?如果我有 android:noHistory="true",那么有 android:finishOnTaskLaunch="true" 有什么意义吗? 最佳答案 假设您的应用中有
我是新手,正在尝试理解以下 XML 代码: 查看 developer.android.com 上的文档,它说“starStyle”是 R.attr 中的常量, public static final
在下面的代码中,为什么当我设置时单选按钮的外观会发生变化 android:layout_width="fill_parent" 和 android:width="fill_parent" 我说的是
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
假设我有一个函数 fun myFunction(name:String, email:String){},当我调用这个函数时 myFunction('Ali', 'ali@test.com ') 如何
我是一名优秀的程序员,十分优秀!