ltu
ltu

Reputation: 177

Android NDK - Library not found

I work with Android Studio and Android NDK. My folder "src/main/jni" contains the following files:

Application.mk APP_ABI := all

Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := HelloWorld
LOCAL_SRC_FILES := HelloWorld.cpp
include $(BUILD_SHARED_LIBRARY)

In my Java code, I load the library:

static{
    System.load("HelloWorld");
}

I run ndk-build as below and it runs without error: ndk-build -C src/main

build.gradle contains:

sourceSets.main {
jniLibs.srcDirs 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}

libHelloWorld.so is compiled and copied to the folders:app\src\main\libs\arm*\

The root directory of app-debug.apk contains a lib directory. libHelloWorld.so exists in all subdirectories (lib\arm*)

When I deploy and debug the application on the LG Nexus 4 device, I get the following error:

9-24 18:50:51.486  20352-20352/ndk.tests.firstndk E/art﹕ dlopen("HelloWorld", RTLD_LAZY) failed: dlopen failed: library "HelloWorld" not found
09-24 18:50:51.489  20352-20352/ndk.tests.firstndk D/AndroidRuntime﹕ Shutting down VM
09-24 18:50:51.491  20352-20352/ndk.tests.firstndk E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: ndk.tests.firstndk, PID: 20352
java.lang.UnsatisfiedLinkError: dlopen failed: library "HelloWorld" not found
at java.lang.Runtime.load(Runtime.java:331)
at java.lang.System.load(System.java:981)
at ndk.tests.firstndk.MainActivity.<clinit>(MainActivity.java:11)
at java.lang.reflect.Constructor.newInstance(Native Method)

Could you please help to solve this issue? Why my native lib cannot be loaded? What is wrong with my configuration?

Upvotes: 2

Views: 3343

Answers (1)

Hong Duan
Hong Duan

Reputation: 4304

try:

static{
    System.loadLibrary("HelloWorld");
}

Upvotes: 5

Related Questions