0
我有我的GNUTLS內的方法.c文件如下如何從.c文件內部調用NDK方法?
int gnutls_error_is_fatal (int error)
{
int ret = 1;
const gnutls_error_entry *p;
/* Input sanitzation. Positive values are not errors at all, and
definitely not fatal. */
if (error > 0)
return 0;
for (p = error_algorithms; p->desc != NULL; p++)
{
if (p->number == error)
{
ret = p->fatal;
break;
}
}
return ret;
}
如何定義它在我的活動類的內部,使得我能夠使用它,並得到一個返回值?
我試過
private native int gnutls_error_is_fatal(int i);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// this is where we call the native code
int hello = gnutls_error_is_fatal(1);
,但它不能正常工作
提供了以下錯誤
E/AndroidRuntime( 756): FATAL EXCEPTION: main
E/AndroidRuntime( 756): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 756): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 756): at java.lang.Class.newInstance(Class.java:1409)
E/AndroidRuntime( 756): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 756): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
E/AndroidRuntime( 756): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/AndroidRuntime( 756): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 756): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
E/AndroidRuntime( 756): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 756): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 756): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 756): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 756): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 756): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 756): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 756): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 756): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load REALGnuTLS: findLibrary returned null
E/AndroidRuntime( 756): at java.lang.Runtime.loadLibrary(Runtime.java:429)
E/AndroidRuntime( 756): at java.lang.System.loadLibrary(System.java:554)
E/AndroidRuntime( 756): at com.test.example.REALGnuTLSActivity.<clinit>(REALGnuTLSActivity.java:12)