简体   繁体   English

android找不到对应的jni函数

[英]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. Android让我找不到对应的JNI函数。

The so files are in jniLibs in the right architecture map. 这样的文件位于正确的体系结构图中的jniLib中。

Has this something to do with my package name that he tries to find it in my package instead of in the so library? 这与我的软件包名称有关,他试图在我的软件包中而不是在so库中找到它?

When I run this I get: 当我运行它时,我得到:

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

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. 如果移动或重命名声明了本机方法的java类,则必须再次编译.so文件,您需要在c文件中更改相应的本机方法名称。 In our case we have video.c file in jni folder . 在我们的例子中,jni文件夹中有video.c文件 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. 我们需要根据将使用此方法的java类的包名称来更新方法名称,并在方法名称前添加“ Java_ ”作为前缀。 Hope this Help. 希望这个帮助。

This is a common problem in jni. 这是jni中的常见问题。

Your native function android class is not able to find the function you are referencing on virtual machine. 您的本机函数android类无法找到您在虚拟机上引用的函数。

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. 有些设备使用armeabi,armeabi-V7等。因此,请尝试在两个版本中交叉编译并放入jniLib中,并为每种体系结构创建文件夹。

  1. Ensure that your function names are correct 确保您的函数名称正确

Firstly check that you are using correct nomenclature in JNI. 首先,检查您在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 如果您的Java包名称是foo.com,并且您定义本机函数的类是JniManager.java,而您的函数是yourFunction

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

If you are using .h files use extern "C". 如果您使用的是.h文件,请使用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
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM