我在android中使用ndk获取签名并转换为md5。我使用javah命令生成jni文件夹,使用ndk build命令生成.so文件。但是在java类中无法获得jni引用的方法。显示为红色,应用程序因以下错误而崩溃
No implementation found for java.lang.String com.sign.signcapture.MainActivity.getToken() (tried Java_com_sign_signcapture_MainActivity_getToken and Java_com_sign_signcapture_MainActivity_getToken__)
10-21 13:04:18.232: D/AndroidRuntime(9040): Shutting down VM
10-21 13:04:18.232: E/AndroidRuntime(9040): FATAL EXCEPTION: main
10-21 13:04:18.232: E/AndroidRuntime(9040): Process: com.sign.signcapture, PID: 9040
10-21 13:04:18.232: E/AndroidRuntime(9040): java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String com.sign.signcapture.MainActivity.getToken() (tried Java_com_sign_signcapture_MainActivity_getToken and Java_com_sign_signcapture_MainActivity_getToken__)
10-21 13:04:18.232: E/AndroidRuntime(9040): at com.sign.signcapture.MainActivity.getToken(Native Method)
10-21 13:04:18.232: E/AndroidRuntime(9040): at com.sign.signcapture.MainActivity.onCreate(MainActivity.java:17)
10-21 13:04:18.232: E/AndroidRuntime(9040): at android.app.Activity.performCreate(Activity.java:6575)
代码是MainActivity.java:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ((TextView) findViewById(R.id.java_sign)).setText(getPackage());
((TextView) findViewById(R.id.jni_sign)).setText(getToken());
}
static {
System.loadLibrary("check-sign");
}
public native String getToken();
// public native String getPackage();
}
签sign.c
jstring Java_com_sign_signcapture_MainActivity__getToken(JNIEnv *env, jobject obj,
jobject context) {
char* signValue = getSignatureMd5(env, obj);
return (*env)->NewStringUTF(env, signValue);
}
答案 0 :(得分:1)
你的C函数名称中有一个拼写错误:
Java_com_sign_signcapture_MainActivity__getToken
Right here --^ Remove the extra _