Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnsatisfiedLinkError: Couldn't load X from loader

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

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

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).

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).

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.

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:

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.

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.

EDIT: Some extra information that might help with identifying the problem.

  • The problem occurs both on osx and windows.
  • The problem occurs on my samsung galaxy s2 and s5, so it is probably not device specific.
  • The problem also occurs on the samples provided with the 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
like image 578
Marth Avatar asked Nov 11 '22 03:11

Marth


1 Answers

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.

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

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.)

like image 97
mstorsjo Avatar answered Nov 14 '22 21:11

mstorsjo