简体   繁体   中英

Android native method is invisible for Java

I am struggling with very annoying error in my code. I have this error appearing over and over again:

    No implementation found for long com.oculus.gles3jni.GLES3JNILib.onCreate(android.app.Activity) 
(tried Java_com_oculus_gles3jni_GLES3JNILib_onCreate and 
Java_com_oculus_gles3jni_GLES3JNILib_onCreate__Landroid_app_Activity_2)

But in my file GLES3JNILib.java I have this:

package com.oculus.gles3jni;

import android.app.Activity;
import android.view.Surface;

// Wrapper for native library

public class GLES3JNILib
{
    // Activity lifecycle
    public static native long onCreate( Activity obj );
    public static native void onStart( long handle );
    public static native void onResume( long handle );
    public static native void onPause( long handle );
    public static native void onStop( long handle );
    public static native void onDestroy( long handle );

    // Surface lifecycle
    public static native void onSurfaceCreated( long handle, Surface s );
    public static native void onSurfaceChanged( long handle, Surface s );
    public static native void onSurfaceDestroyed( long handle );

    // Input
    public static native void onKeyEvent( long handle, int keyCode, int action );
    public static native void onTouchEvent( long handle, int action, float x, float y );
}

So I am not sure what is wrong. It is there but still I can't start my app. In my cpp code the implementation is:

jlong Java_com_oculus_gles3jni_GLES3JNILib_onCreate( JNIEnv * env, jobject obj, jobject activity )
{
...
}

Does someone see what I am missing, or doing wrong? Is it possible that this is because I don't have h file for my cpp?

You must have generated the C code and then changed the Java native method declaration to static without re-running javah .

Or you didn't run it at all and tried to wing it. Don't do that.

The correct signature has jclass for the second parameter, but don't take my word for it: rerun javah and adjust your .c file accordingly.

NB your .c file should #include your .h file.

Did you forget to load the library?

public class GLES3JNILib
{
   static {
      try {
        System.loadLibrary("libGLES3JNILib");
      } catch (UnsatisfiedLinkError e) {
          // do something helpful here
      }
  }

  ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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