什么是写的Andr​​oid NDK本地方法签名的正确方法是什么? [英] What is the correct way to write native method signatures in Android NDK?

查看:133
本文介绍了什么是写的Andr​​oid NDK本地方法签名的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有NDK库和相应的Java类的工作实现。但我不能够重载方法添加到类。目前我的类包含:

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");
  }
}

我jniwrappers.cpp文件具有以下声明:

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);
  ...
}

和添加到jniwrappers.cpp另一声明:

And add to jniwrappers.cpp another declaration:

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

它编译罚款,Android应用程序启动时,没有得到的UnsatisfiedLinkError但是当它调用第二个方法与参数的第一个C ++函数被调用,但没有第二个。我有其他的方法,在该类论点,但他们都不超载所以它们各自的JNI签名不包含的参数。

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?

推荐答案

您必须添加一个 __ 到原来的getFileName函数的结束,现在它是超载。您2 C函数原型现在应该是这样的:

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);

这篇关于什么是写的Andr​​oid NDK本地方法签名的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆