Issue
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).
Solution
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.
Answered By - richq
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.