3
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 ?

Dauezevy
  • 1,012
  • 4
  • 22
  • 46

3 Answers3

0

Try this:

System.loadLibrary("kdu_jni");

loadLibrary() actually load from the ape's lib/. Also you don't need to specify 'lib' & the extension 'so'.

Hope this helps.

us_david
  • 4,431
  • 35
  • 29
0

I have same problem with other .so file. I added jniLibs library to ...src/main with the relevant file and it worked. Maybe you can try it to.

Eliran Goshen
  • 83
  • 1
  • 11
0

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, this 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
)
tanius
  • 14,003
  • 3
  • 51
  • 63