Dinesh Krishnan
Dinesh Krishnan

Reputation: 51

android cannot find corresponding jni function

public native static int convertVideoFrame(ByteBuffer src, 
                                          ByteBuffer dest, 
                                          int destFormat, 
                                          int width, 
                                          int height, 
                                          int padding, 
                                          int swap);

Android gives me that he cannot find the corresponding JNI function.

The so files are in jniLibs in the right architecture map.

Has this something to do with my package name that he tries to find it in my package instead of in the so library?

When I run this I get:

No implementation found for native Lorg/telegram/Utilities;.
    convertVideoFrame:(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;IIIII)I

Upvotes: 2

Views: 1910

Answers (2)

uelordi
uelordi

Reputation: 2209

This is a common problem in jni.

Your native function android class is not able to find the function you are referencing on virtual machine.

There are different ways to reproduce this error:

  1. Your target architecture:

Some devices uses armeabi,armeabi-V7 etc. So try to crosscompile in both versions and put into jniLibs and create folder for each architecture.

  1. Ensure that your function names are correct

Firstly check that you are using correct nomenclature in JNI. if your java package name is foo.com and your class where you define native functions is JniManager.java and your function is yourFunction

JNIEXPORT jint JNICALL
            Java_foo_com_JniManger_yourFunction(JNIEnv *env,jobject instance);

If you are using .h files use extern "C".

extern "C"
{
  JNIEXPORT jint JNICALL Java_foo_com_JniManger_yourFunction(JNIEnv*env,jobject instance);
  JNIEXPORT jint JNICALL Java_foo_com_JniManger_yourFunction(JNIEnv*env,jobject instance)
    {
       //your body
    }
}

Upvotes: 1

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20910

You have to compile the .so file again if you move or rename the java class in which native method is declared you need to change the corresponding native method name in c file. In our case we have video.c file in jni folder. We need to update the method name according to the package name of java class which will be using this method and also adding "Java_" as prefix to method name. Hope this Help.

Upvotes: 2

Related Questions