Android的NDK" java.lang.UnsatisfiedLinkError中" [英] Android-NDK "java.lang.UnsatisfiedLinkError"
问题描述
我是新来NDK和以及C,C ++。所以如果我错了,请原谅我。
I am new to NDK and as well as c, c++. so If I am mistaken please forgive me.
在登录猫我得到的错误是 java.lang.UnsatisfiedLinkError中
NDK的构建后,我可以看到在lib文件夹 libfirst-opengl.so
库
The error in Log cat I am getting is java.lang.UnsatisfiedLinkError
After ndk-build I can see the libfirst-opengl.so
library in lib folder
听到的是我的code为JAVA
Hear is my code for JAVA
public class MainActivity extends Activity {
private GLSurfaceView mGLSurfaceView;
/** Called when the activity is first created. */
static{
System.loadLibrary("first-opengl");
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set window full screen and remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Create the EGL surface (set OpenGL version 2.0) and override the
// renderer with our custom one
mGLSurfaceView = new GLSurfaceView(this);
mGLSurfaceView.setEGLContextClientVersion(2);
mGLSurfaceView.setRenderer(new MySurfaceViewRenderer());
setContentView(mGLSurfaceView);
}
@Override
public void onPause() {
super.onPause();
mGLSurfaceView.onPause();
}
@Override
public void onResume() {
super.onResume();
mGLSurfaceView.onResume();
}
public class MySurfaceViewRenderer implements Renderer {
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
JNIOnSurfaceCreated();
}
public void onSurfaceChanged(GL10 unused, int w, int h) {
JNIOnSurfaceChanged(w, h);
}
public void onDrawFrame(GL10 unused) {
JNIOnDrawFrame();
}
private native void JNIOnSurfaceCreated();
private native void JNIOnSurfaceChanged(int w, int h);
private native void JNIOnDrawFrame();
}
}
code为C ++文件。
code for C++ file is..
#include <jni.h>
#include <string.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <stdio.h>
#include <stdlib.h>
#include <android/log.h>
#define LOG_TAG "opengl-first"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
void surfaceCreated(){
const GLubyte* puiOpenGLVersion = glGetString(GL_VERSION);
LOGI("OpenGL Version: \"%s\"\n", (char*)puiOpenGLVersion);
}
void surfaceChanged(int w, int h){
LOGI("JNIOnSurfaceChanged %dx%d\n", w, h);
glViewport(0, 0, w, h);
}
void drawFrame(){
// Clear the screen to a random shade of grey
float fColor = (float)(rand() % 256) / 255.0f;
glClearColor(fColor, fColor, fColor, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
extern "C" {
JNIEXPORT void JNICALL Java_com_nix_opendk_MainActivity_JNIOnDrawFrame(JNIEnv* env, void* reserved);
JNIEXPORT void JNICALL Java_com_nix_opendk_MainActivity_JNIOnSurfaceChanged(JNIEnv* env, void* reserved, int w, int h);
JNIEXPORT void JNICALL Java_com_nix_opendk_MainActivity_JNIOnSurfaceCreated(JNIEnv* env, void* reserved);
};
JNIEXPORT void JNICALL Java_com_nix_opendk_MainActivity_JNIOnSurfaceCreated(JNIEnv* env, void* reserved)
{
surfaceCreated();
}
JNIEXPORT void JNICALL Java_com_nix_opendk_MainActivity_JNIOnSurfaceChanged(JNIEnv* env, void* reserved, int w, int h)
{
surfaceChanged(w,h);
}
JNIEXPORT void JNICALL Java_com_nix_opendk_MainActivity_JNIOnDrawFrame(JNIEnv* env, void* reserved)
{
drawFrame();
}
和我的make文件: -
and My make file:-
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog -lGLESv2
LOCAL_CFLAGS := -Werror
LOCAL_MODULE := first-opengl
LOCAL_SRC_FILES := opengl-first.cpp
include $(BUILD_SHARED_LIBRARY)
我不知道这是genrating错误的部分,所以我增加了我所有的code
I wasn't aware of the part which is genrating error so I have added my all code
请帮我这一点。
感谢您
推荐答案
本机功能都在MySurfaceViewRenderer渲染器类不MainActivity这样:
your native functions are in the MySurfaceViewRenderer renderer class not MainActivity so:
JNIEXPORT void JNICALL Java_com_nix_opendk_MainActivity_JNIOnDrawFrame
也许应该是:
JNIEXPORT void JNICALL Java_com_nix_opendk_MainActivity_MySurfaceViewRenderer_JNIOnDrawFrame
我还没有尝试在JNI来访问内部类,但似乎基于规范健全。
I haven't attempted to access an inner class in jni but that seems sound based on the spec.
这篇关于Android的NDK&QUOT; java.lang.UnsatisfiedLinkError中&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!