UnsatisfiedLinkError:无法从加载器加载X [英] UnsatisfiedLinkError: Couldn't load X from loader

查看:115
本文介绍了UnsatisfiedLinkError:无法从加载器加载X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用本机代码调用OpenGl函数来创建一个android项目.

I am trying to make an android project using native code to call OpenGl function.

我正在遵循此指南来开展这一项目: http://www.learnopengles.com/calling-opengl-来自android-using-the-ndk/

I am following this guide to getting this project of the ground: http://www.learnopengles.com/calling-opengl-from-android-using-the-ndk/

根据本指南,我必须在Package Explorer中右键单击该项目,从下拉菜单中选择Android Tools,然后选择Add Native Support….".但是,此选项在我的eclipse版本(与sdk捆绑在一起的android网站中的最新osx版本)中不可见.

According to this guide I have to "right-click on the project in the Package Explorer, select Android Tools from the drop-down menu, then select Add Native Support….". However, this option is not visible in my version of eclipse (latest osx version from the android site bundled with the sdk).

要解决此问题,我使用以下方法将项目手动转换为C/C ++项目: 文件->新->其他->转换为C/C ++项目(添加C/C ++支持).

To work around this, I manually converted the project to a C/C++ Project using: file -> new -> other -> Convert to a C/C++ Project(Adds C/C++ support).

然后我将PATH变量添加到在项目属性-> C/C ++ build->环境下找到的环境变量中.然后我将ndk的路径添加到此变量中.

I then added the PATH variable to Environment variables found under the project properties -> C/C++ build -> Environment. And I added the path to the ndk to this variable.

我还制作了必要的make文件并生成了jni文件. 该项目确实在libs目录中编译并生成一个.so文件. 但是,当我尝试在设备上运行项目时,出现以下运行时错误:

Further more I made the necessary make-files and generated the jni file. The project does compile and generate a .so file in the libs directory. However, when I try to run the project on a device I get the following runtime error:

java/lang/UnsatisfiedLinkError异常;初始化nl/blaat/project_name/JNIWrapper时抛出; java.lang.UnsatisfiedLinkError:无法从加载程序dalvik.system.PathClassLoader [dexPath =/data/app/nl.blaat.project_name.

Exception java/lang/UnsatisfiedLinkError; thrown while initializing nl/blaat/project_name/JNIWrapper; java.lang.UnsatisfiedLinkError: Couldn't load GLCore from loader dalvik.system.PathClassLoader[dexPath=/data/app/nl.blaat.project_name.

当我在线搜索时,对该问题的通常答案是本机代码未编译,但就我而言是编译的. NDK提供的示例项目也存在相同的问题.

When I search online, the usual answer to the problem is that the native code did not compile, but in my case it does. The example projects provided by the NDK give the same problem.

一些其他信息可能有助于识别问题.

  • 该问题同时出现在osx和Windows上.
  • 该问题发生在我的三星银河s2和s5上,因此它可能不是特定于设备的.
  • SDK随附的示例上也会出现此问题.

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := OpenGLCore
LOCAL_CFLAGS    := -Wall -Wextra
LOCAL_SRC_FILES := OpenGLCore.c jni.c
LOCAL_LDLIBS := -lGLESv2

include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_PLATFORM := android-10
APP_ABI := all

推荐答案

如果NDK中的示例项目给出了相同的错误,您确定它是针对正确的体系结构构建的吗?大多数android设备运行ARM处理器,但是有些android设备运行在x86和mips上,并且许多NDK示例默认情况下仅针对ARM构建.

If the example projects from the NDK give the same error, are you sure it's built for the right architecture? Most android devices run ARM processors, but some run on x86 and mips, and many NDK samples by default only build for ARM.

要针对所有体系结构进行构建,请在jni/Application.mk中添加"APP_ABI:= all".

To build for all architectures, add "APP_ABI := all" to jni/Application.mk.

此外,为确保您调整后的构建过程确实有效,请尝试通过手动在终端中的NDK示例的终端中在项目根目录中运行ndk-build来构建.so. (此后,您可能需要刷新eclipse中的文件夹结构,以确保找到并包含了新建的库.)

Also, to make sure your adjusted build process actually works, try building the .so by running ndk-build in a terminal manually, in the project root, for a NDK sample first. (You might need to refresh the folder structure in eclipse after this, to make sure the newly built libs are found and included.)

这篇关于UnsatisfiedLinkError:无法从加载器加载X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆