Pergunta

I have this code in java:

public native String hello(String inputs, String modems, String outputs);

and this code in C:

JNIEXPORT jstring JNICALL Java_com_marakana_NativeLib_hello(JNIEnv * env, jobject obj, jstring inputs, jstring modems, jstring outputs)

and I have conflicting types error:

error: conflicting types for 'Java_com_marakana_NativeLib_hello'
note: previous declaration of 'Java_com_marakana_NativeLib_hello' was here 
make.exe: *** [C:/workspace/marakana//obj/local/armeabi-v7a/objs/ndk_demo/ndk_demo.o] Error 1

I tried an example like that and it worked (but with int). what is the problem?

Foi útil?

Solução

When building jni code, you have to ensure that the header file generated using javah matches the native declarations from the .class file.

When you change the native method signature, you have to:

  1. Recompile the .java file
  2. Regenerate the .h file from the resulting .class file
  3. Make sure that the signature of the definition in the .c file matches the declaration in the .h file

If you miss any of the steps, you can end up being unable to recompile the .c file, or end up with a non-functional native library that won't load in the VM.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top