Android出现SIGSEGV/SEGV_MAPERR崩溃
创始人
2024-10-06 19:01:28
0

这是由于访问了错误的地址或者内存越界所导致的错误。一般会伴随着Native层的异常。 可以通过调试或者Crash日志等手段来排查这个问题。 代码示例:

public class NativeCrashActivity extends AppCompatActivity {

    private TextView crashText;

    static {
        System.loadLibrary("native-lib");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_native_crash);

        crashText = findViewById(R.id.crash_text);

        //调用Native方法,模拟出现Segmentation fault错误
        int[] array = {0, 1};
        int result = funcWithSegmentationFault(array);
        Log.d("NativeCrashActivity", "result: " + result);

    }

    public void onCrashClick(View view) {
        //调用Native方法,模拟出现SIGSEGV错误
        int[] array = null;
        int result = funcWithSIGSEGV(array);
        Log.d("NativeCrashActivity", "result: " + result);
    }

    public void onCrashInThreadClick(View view) {
        //创建子线程调用Native方法,模拟出现SIGSEGV错误
        new Thread(new Runnable() {
            @Override
            public void run() {
                int[] array = null;
                int result = funcWithSIGSEGV(array);
                Log.d("NativeCrashActivity", "result: " + result);
            }
        }).start();
    }

    //Native方法,模拟出现SIGSEGV错误
    public native int funcWithSIGSEGV(int[] array);

    //Native方法,模拟出现Segmentation fault错误
    public native int funcWithSegmentationFault(int[] array);

}
JNIEXPORT jint JNICALL
Java_com_example_nativecrash_NativeCrashActivity_funcWithSIGSEGV(JNIEnv *env, jobject thiz,
                                                                jintArray array) {
    jsize length = (*env)->GetArrayLength(env, array);

    jint *arr = (*env)->GetIntArrayElements(env, array, NULL);

相关内容

热门资讯

透视神器!wepoker手机版... 透视神器!wepoker手机版透视脚本(透视)wepoker辅助工具(竟然一直都是有透视)-哔哩哔哩...
透视教程!wepoker免费脚... 透视教程!wepoker免费脚本(透视)wepoker免费辅助器(总是有挂)-哔哩哔哩1、玩家可以在...
透视app!wepokerpl... 透视app!wepokerplus作必弊(透视)wepoker透视是真的吗(真是有脚本)-哔哩哔哩一...
透视工具!德扑之心免费透视(透... 透视工具!德扑之心免费透视(透视)德普之星怎么开辅助(果然一直都是有脚本)-哔哩哔哩1、德普之星怎么...
透视app!wepoker线上... 透视app!wepoker线上大神(透视)黑侠破解wepoker(都是是有辅助器)-哔哩哔哩1.黑侠...
透视方法!hhpoker作必弊... 透视方法!hhpoker作必弊码怎么用(透视)hhpoker透视脚本下载(一贯真的有挂)-哔哩哔哩1...
透视app!德普之星的辅助工具... 透视app!德普之星的辅助工具介绍(透视)德普之星辅助工具如何设置(其实是有透视)-哔哩哔哩1、在德...
透视教程!越乡游义乌辅助器(辅... 透视教程!越乡游义乌辅助器(辅助)圣游辅助软件(原来是真的有辅助器)-哔哩哔哩1、起透看视 越乡游义...
透视攻略!hhpoker是正品... 透视攻略!hhpoker是正品吗(透视)hhpoker真的有透视吗(确实真的有挂)-哔哩哔哩1、hh...
透视工具!德普之星私人局辅助免... 透视工具!德普之星私人局辅助免费(透视)德普之星透视(一贯是有辅助器)-哔哩哔哩1、起透看视 德普之...