I have a java class with two native functions with same names but different parameters.
package com.example;
public class Test {
static {
System.loadLibrary("TestLib");
}
public static native void doSomething(int a);
public static native void doSomething(int a, long b);
}
My header file looks like
#include <jni.h>
#ifndef _TEST_LIB_H_
#define _TEST_LIB_H_
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_com_example_Test_doSomething
(JNIEnv *env, jclass clazz, jint a);
JNIEXPORT void JNICALL Java_com_example_Test_doSomething
(JNIEnv *env, jclass clazz, jint a, jlong b);
#ifdef __cplusplus
}
#endif
#endif //_TEST_LIB_H_
and my cpp file
#include "TestLib.h"
JNIEXPORT void JNICALL Java_com_example_Test_doSomething
(JNIEnv *env, jclass clazz, jint a){
Java_com_example_Test_doSomething(env, clazz, a, -1);
}
JNIEXPORT void JNICALL Java_com_example_Test_doSomething
(JNIEnv *env, jclass clazz, jint a, jlong b) {
// implementation
}
with only one function it works, but after add a second one with same name and different parameters I get an error:
error: conflicting declaration of C function 'void Java_com_example_Test_doSomething(JNIEnv*, jclass, jint, jlong)'
note: previous declaration 'void Java_com_example_Test_doSomething(JNIEnv*, jclass, jint)'
I'm using android studio and experimental gradle plugin. What am I doing wrong?