Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dlopen("xxxx") failed: dlopen failed: library "xxxx" not found

Tags:

java

android

package com.test.nativeapp;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

    static {
        try {
            System.load("native/libkdu_jni.so");
        } catch (UnsatisfiedLinkError e) {
          System.err.println("Native code library failed to load.\n" + e);
          System.exit(1);
        }
      }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

LogCat Error:

06-18 11:13:55.235: D/dalvikvm(17658): Trying to load lib native/libkdu_jni.so 0x421eeb38 06-18 11:13:55.235: E/dalvikvm(17658): dlopen("native/libkdu_jni.so") failed: dlopen failed: library "native/libkdu_jni.so" not found

06-18 11:13:55.235: W/System.err(17658): Native code library failed to load.

06-18 11:13:55.235: W/System.err(17658): java.lang.UnsatisfiedLinkError: dlopen failed: library "native/libkdu_jni.so" not found

Where should i put this folder ?

like image 397
Dauezevy Avatar asked Nov 17 '25 18:11

Dauezevy


1 Answers

With System.load("…"); you are loading a library in a way that is undetectable by the Android APK packaging code of your build system. Due to this, the library is not included into the APK and cannot be found at runtime when you start the app on an Android device.

To solve this, use the mechanism of your build system to make the APK packager aware of extra libraries to include. This will differ between build systems. As an example, in a CMake build system you would just add the library to the list of libraries in target_link_libraries(…):

add_executable(my_executable_name ${SRCS} ${RESOURCES})

# Link all required libraries with the executable, 
# and include them into the Android APK.
target_link_libraries(my_executable_name
    # Name libraries here as you would when calling "g++ -l…".
    # Alternatively, use absolute paths.
    Qt5::Core
    Qt5::Quick
    /my/path/to/native/libkdu_jni.so
)
like image 164
tanius Avatar answered Nov 19 '25 08:11

tanius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!