gpt4 book ai didi

Android-NDK "java.lang.UnsatisfiedLinkError"

转载 作者:搜寻专家 更新时间:2023-11-01 09:07:25 25 4
gpt4 key购买 nike

我是 NDK 以及 c、c++ 的新手。所以如果我错了请原谅我。

我收到的 Log cat 错误是 java.lang.UnsatisfiedLinkError在 ndk-build 之后,我可以在 lib 文件夹中看到 libfirst-opengl.so

听说是我的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();
}

}

C++ 文件的代码是..

#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 文件:-

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)

我不知道产生错误的部分所以我添加了我的所有代码

请帮助我。

谢谢

最佳答案

您的 native 函数位于 MySurfaceViewRenderer 渲染器类中,而不是 MainActivity,因此:

JNIEXPORT void JNICALL Java_com_nix_opendk_MainActivity_JNIOnDrawFrame

应该是:

JNIEXPORT void JNICALL Java_com_nix_opendk_MainActivity_MySurfaceViewRenderer_JNIOnDrawFrame

我没有尝试访问 jni 中的内部类,但根据规范,这似乎是合理的。

关于Android-NDK "java.lang.UnsatisfiedLinkError",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10862208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com