views:

28

answers:

2

I have a working implementation of NDK library and corresponding Java-class. But I am not able to add overloaded method to that class. Currently my class contains:

package com.package;

public class MyClass
{
  public static native String getFileName();
  static
  {
    System.loadLibrary("mylib");
  }
}

My jniwrappers.cpp file has the following declaration:

JNIEXPORT jstring JNICALL
Java_com_package_MyClass_getFileName(_JNIEnv* env, jobject thiz);

Up to this point everything is working fine. But next I modify my class:

package com.package;

public class MyClass
{
  public static native String getFileName();
  public static native String getFileName(int index);
  ...
}

And add to jniwrappers.cpp another declaration:

JNIEXPORT jstring JNICALL
Java_com_package_MyClass_getFileName__I(_JNIEnv* env, jobject thiz, jint index);

It compiles fine, Android application starts, does not get UnsatisfiedLinkError but when it calls the second method with the argument the first C++ function is being called but not the second. I have other methods with arguments in that class but none of them are overloaded so their respective JNI signatures do not contain arguments.

So, what am I doing wrong?

+2  A: 

You have to add a __ onto the end of the original getFileName function now that it is overloaded. Your 2 C function prototypes should now look like this:

JNIEXPORT jstring JNICALL Java_com_package_MyClass_getFileName__
  (JNIEnv *, jclass);

JNIEXPORT jstring JNICALL Java_com_package_MyClass_getFileName__I
  (JNIEnv *, jclass, jint);
rq
This was the first thing that I tried but something went wrong and I've got UnsatisfiedLinkError. Now I have retried this and got everything working. Thanks a lot!
Andrey Novikov