Matt
Matt

Reputation: 3652

UnsatisfiedLinkError when trying to load library that is clearly there

I'm using prebuilt libs (libsox.so et al) and I'm using a small test file for the JNI interface (sox-test-jni.so). I'm trying to load "sox" and "sox-test-jni" via System.loadLibrary and I'm getting an UnsatisfiedLinkError at run-time.

I previously built libsox.so et al with NDK.

When I run ndk-build, everything seems fine and all required files are put in into libs/armeabi-v7a/

When running my Java app on a phone, the error is:

Cannot load library: link_image[1963]:  1413 could not load needed library 'liblpc10.so' for 'libsox.so' (load_library[1105]: Library 'liblpc10.so' not found)

So apparently it finds libsox.so just fine but can't find liblpc10.so, which lives right next to it.

These are the libs in my APK file - in libs/armeabi-v71/

libffmpeg.so
libFLAC.so
libfmemopen.so
libgsm.so
liblpc10.so
libmad.so
libmp3lame.so
libogg.so
libplayer.so
libpng.so
libsmr.so
libsmrx.so
libsndfile.so
libsox.so
libsox-test-jni.so
libvorbis.so
libvorbisenc.so
libvorbisfile.so
libwavpack.so

Here's my Android.mk for the JNI stuff.

http://pastebin.com/raw.php?i=dcSijYSv

Here's my Java:

package roman10.ffmpegTest;

import android.app.ListActivity;
import android.widget.AbsListView;
import android.widget.ListView;

public class VideoBrowser extends ListActivity implements ListView.OnScrollListener {

  //load the native library
  static {
      System.loadLibrary("sox");
      System.loadLibrary("sox-test-jni");
    }

    @Override
    public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
    } 
}

Upvotes: 1

Views: 4293

Answers (3)

mo. shakir qureshi
mo. shakir qureshi

Reputation: 11

Try this:

static {
   try{
      System.loadLibrary("ffmpeg-prebuilt");// ffmpeg in some code as android.mk module name
      System.loadLibrary("ffmpeg-test-jni");
   }
   catch (UnsatisfiedLinkError e) {
       Log.e("Error..1", e.toString());
   }
}

Upvotes: 1

Matt
Matt

Reputation: 3652

Looks like I need to tell explicitly Java to load any dependencies. It won't figure them out on it's own even though it knows it wants "liblpc10.so" it won't automatically load it.

  System.loadLibrary("ffmpeg");
  System.loadLibrary("ogg");
  System.loadLibrary("lpc10");
  System.loadLibrary("gsm");
  System.loadLibrary("vorbis");
  System.loadLibrary("vorbisenc");
  System.loadLibrary("vorbisfile");
  System.loadLibrary("FLAC");
  System.loadLibrary("fmemopen");
  System.loadLibrary("mad");
  System.loadLibrary("mp3lame");
  System.loadLibrary("smr");
  System.loadLibrary("png");
  System.loadLibrary("smrx");
  System.loadLibrary("sndfile");
  System.loadLibrary("wavpack");      
  System.loadLibrary("sox");
  System.loadLibrary("sox-test-jni");

Upvotes: 1

eplewis89
eplewis89

Reputation: 112

Android.mk is used for the compilation of your source code, not pre-compiled .so's:

#AMR
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := amr
LOCAL_C_INCLUDES := amr/c
LOCAL_SRC_FILES :=  \
    amr/c/sp_enc.cpp \
    amr/c/interf_enc.cpp \
    amr/c/interf_dec.cpp \
    amr/c/sp_dec.cpp \
    amr/amr.cpp
TARGET_ARCH_ABI := armeabi-v7a
include $(BUILD_SHARED_LIBRARY)

If you just do a load library on your so's rather than including them in the compilation procedure, you should have a better outcome. Also, maybe you can try to rename the libraries? I ran into the issue of a phone crashing because I was loading a library named "mss" when, in fact, there was a library by that name already on the phone. (Renaming my library took care of this issue.)

Upvotes: 0

Related Questions