我正在研究使用NDK 9编译Android 5或更高版本的本机代码是否有任何问题但尚未找到任何答案。 我已经在source.android.com上进行了长时间的搜索, 这个页面离我更接近回答但是还不清楚......
我问这个是因为我在用C编写的本机代码中遇到了一个SIGSEGV问题,要放在我的Android应用程序中。 在Android 5之前,代码运行顺利,但在使用android 5或者superior的每个设备中都会偶尔出现此错误(有时代码运行时没有错误)。
I'm making a research about if there is any problem in compiling native code for Android 5 or superior using NDK 9 but couldn't yet find any answer. I already made a long search in source.android.com, this page was the closer I could get to answering but it is not clear yet...
I'm asking this because I'm having a SIGSEGV problem in a native code written in C to be put in my Android app. Before Android 5, the code run smoothly but in every device using android 5 or superior gives this error ocasionally (sometimes the code runs without error).
最满意答案
对于NDK版本,应该没问题。 这是一个较旧的年份,但仍应正确构建您的代码。 我会尽快尝试更新,只是为了保持最新状态。 我不认为这会导致崩溃。
Android 5默认引入了Android Runtime(ART) 。 在此之前,使用的VM是Dalvik 。 我发现Android 5中的JNI层更加严格。 在旧的Dalvik世界中,你可以经常逃脱,例如,在JNI调用之间共享一个JNIEnv指针。 在ART中,这是不可能的,并且总会崩溃。 为了清楚起见,在达尔维克它不应该工作,但你可以逃脱它,所以错误未被发现。
另外需要注意的是在堆栈上创建大型局部变量,例如数组。 在Dalvik中,每个线程有2个堆栈,一个用于JNI代码,一个用于Java,但在ART中,堆栈在本机和Java之间共享。 因此JNI代码可能会耗尽堆栈并崩溃。 这些类型的崩溃可能很难追查。 寻找本地(非malloc'd)数组的代码检查是我过去发现的一种方式。
是否有来自logcat的良好堆栈跟踪? 通常,您可以通过在调试中构建并通过ndk-stack传递堆栈跟踪来调试SIGSEGV。 如果您很幸运,它会为您提供代码崩溃的行。
For the NDK version, it should be fine. It's an older vintage but should still build your code correctly. I'd try and update as soon as you can though, just to keep current. I don't think this would be the cause of the crash.
Android 5 introduced the Android Runtime (ART) by default. Prior to this the VM used was Dalvik. I found that the JNI layer in Android 5 was a lot stricter. In the old Dalvik world you could often get away with, for example, sharing a JNIEnv pointer between JNI calls. In ART this is not possible and will always crash. Just to be clear, in Dalvik it should not work either but you could get away with it, so the mistake went undetected.
Another thing to watch out for is creating large local variables, such as arrays, on the stack. In Dalvik each thread had 2 stacks, one for JNI code and one for Java, but in ART the stack is shared between native and Java. So the JNI code may be running out of stack and crashing. These kinds of crashes can be very difficult to track down. Code inspection looking for local (non-malloc'd) arrays has been the way I've found some in the past.
Is there a good stack trace from logcat? Usually you can debug a SIGSEGV by building in debug and passing the stack trace through ndk-stack. If you're lucky it gives you the line where your code crashes.
使用NDK 9 for Android 5.0或更高版本构建的应用程序之间是否存在不兼容性?(Is there incompatibility between apps built using NDK 9 for Android 5.0 or superior?)我正在研究使用NDK 9编译Android 5或更高版本的本机代码是否有任何问题但尚未找到任何答案。 我已经在source.android.com上进行了长时间的搜索, 这个页面离我更接近回答但是还不清楚......
我问这个是因为我在用C编写的本机代码中遇到了一个SIGSEGV问题,要放在我的Android应用程序中。 在Android 5之前,代码运行顺利,但在使用android 5或者superior的每个设备中都会偶尔出现此错误(有时代码运行时没有错误)。
I'm making a research about if there is any problem in compiling native code for Android 5 or superior using NDK 9 but couldn't yet find any answer. I already made a long search in source.android.com, this page was the closer I could get to answering but it is not clear yet...
I'm asking this because I'm having a SIGSEGV problem in a native code written in C to be put in my Android app. Before Android 5, the code run smoothly but in every device using android 5 or superior gives this error ocasionally (sometimes the code runs without error).
最满意答案
对于NDK版本,应该没问题。 这是一个较旧的年份,但仍应正确构建您的代码。 我会尽快尝试更新,只是为了保持最新状态。 我不认为这会导致崩溃。
Android 5默认引入了Android Runtime(ART) 。 在此之前,使用的VM是Dalvik 。 我发现Android 5中的JNI层更加严格。 在旧的Dalvik世界中,你可以经常逃脱,例如,在JNI调用之间共享一个JNIEnv指针。 在ART中,这是不可能的,并且总会崩溃。 为了清楚起见,在达尔维克它不应该工作,但你可以逃脱它,所以错误未被发现。
另外需要注意的是在堆栈上创建大型局部变量,例如数组。 在Dalvik中,每个线程有2个堆栈,一个用于JNI代码,一个用于Java,但在ART中,堆栈在本机和Java之间共享。 因此JNI代码可能会耗尽堆栈并崩溃。 这些类型的崩溃可能很难追查。 寻找本地(非malloc'd)数组的代码检查是我过去发现的一种方式。
是否有来自logcat的良好堆栈跟踪? 通常,您可以通过在调试中构建并通过ndk-stack传递堆栈跟踪来调试SIGSEGV。 如果您很幸运,它会为您提供代码崩溃的行。
For the NDK version, it should be fine. It's an older vintage but should still build your code correctly. I'd try and update as soon as you can though, just to keep current. I don't think this would be the cause of the crash.
Android 5 introduced the Android Runtime (ART) by default. Prior to this the VM used was Dalvik. I found that the JNI layer in Android 5 was a lot stricter. In the old Dalvik world you could often get away with, for example, sharing a JNIEnv pointer between JNI calls. In ART this is not possible and will always crash. Just to be clear, in Dalvik it should not work either but you could get away with it, so the mistake went undetected.
Another thing to watch out for is creating large local variables, such as arrays, on the stack. In Dalvik each thread had 2 stacks, one for JNI code and one for Java, but in ART the stack is shared between native and Java. So the JNI code may be running out of stack and crashing. These kinds of crashes can be very difficult to track down. Code inspection looking for local (non-malloc'd) arrays has been the way I've found some in the past.
Is there a good stack trace from logcat? Usually you can debug a SIGSEGV by building in debug and passing the stack trace through ndk-stack. If you're lucky it gives you the line where your code crashes.
发布评论