2

I'm using Kotlin and JNI as I'm looking to port a C program to Android and I'm wondering why I'm currently getting an "art_sigsegv_fault" as soon as the JNI function's breakpoint is hit.

Kotlin code:

import com.root.Main

class SettingsScreenActivity : AppCompatActivity() {

    private val MainC = Main()

    fun startButton(view: View)
        MainC.callMainFromJNI("test")
    }
}

MainC.c

JNIEXPORT void JNICALL Java_com_root_hping2_Main_callMainFromJNI(JNIEnv *env, jobject pThis, jstring argument){

    printf("Size of char: %ld byte\n",sizeof(char));
    return;
}

Breakpoint is on the printf , however, when I go to debug, I get the "art_sigsegv_fault" error and I'm not able to see any of the values of the parameters. This is within Android Studio

EDIT: When i remove the jstring argument and don't pass the string into the function, it works correctly. What would the reason for this be?

scaborski
  • 145
  • 16
  • Unable to reproduce (using the emulator). Please provide a Minimal, Complete, and Verifiable Example. – Michael Jan 30 '19 at 13:11
  • I'm having the same problem, only it's from Java, not Kotlin, and the JNI file is straight C, not C++. If I take the jstring argument out of everything, it works, and the debugger lets me single-step through the JNI code, with a successful return. But if I add the jstring argument back in, and adjust the class declaration to provide a string as an argument, I get the same crash with a "art_sigsegv_fault" reported. The function takes an earlier jint argument, which is what worked without the second jstring argument. Seems clearly related to the added jstring argument, though it might not. – jsbox Jan 04 '20 at 00:20

1 Answers1

4

Answer is within: Different behavior of Native C++ Android projects when using Java and Kotlin as a base language

It looks to be a bug regarding the API Emulator and which version is being used. If the version is downgraded to API 25, no issues. As well, if the application is built on a device rather than an emulator will help with this issue.

scaborski
  • 145
  • 16