安卓.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := pacman
LOCAL_SRC_FILES := main.cpp \
Pacman.cpp
LOCAL_CFLAGS := -DANDROID_NDK \
-DDISABLE_IMPORTGL
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog
include $(BUILD_SHARED_LIBRARY)
在 main.cpp 中:
void Java_com_wiagames_pacman_PacmanRenderer_nativeInit(JNIEnv* env) {
...
}
包是 com.wigames.pacman;包含 nativeInit 方法的 Java 类是 com.wigames.pacman 包中的 PacmanRenderer。在我添加 pacman.cpp 之前它工作正常,但在添加它之后我有:
E/AndroidRuntime( 2238): FATAL EXCEPTION: GLThread 1104
E/AndroidRuntime( 2238): java.lang.UnsatisfiedLinkError: Native method not found: com.wiagames.pacman.PacmanRenderer.nativeInit:()V
E/AndroidRuntime( 2238): at com.wiagames.pacman.PacmanRenderer.nativeInit(Native Method)
E/AndroidRuntime( 2238): at com.wiagames.pacman.PacmanRenderer.onSurfaceCreated(MainActivity.java:120)
E/AndroidRuntime( 2238): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494)
E/AndroidRuntime( 2238): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
W/ActivityManager( 306): Force finishing activity com.wiagames.pacman/.MainActivity
main.c: http: //pastebin.com/GPexqwcv
MainActivity.java:http://pastebin.com/yWfWpyNb _