java.lang.UnsatisfiedLinkError: Couldn’t load jni-input: findLibrary returned null

Issue

First,I use NDK in the MainActivity,it works fine.:

public class MainActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    EventInput eventInputnew EventInput();
    textView.setText(eventInput.eventInject());// NDK
}
}

EventInput.java like this:

public class EventInput {
static {
    System.loadLibrary("jni-input");
}
public native String eventInject();
}

Then,I remove the MainActivity and in the boot broadcast receiver I start a service ,and used ndk in service`s onCreate method,like this:

  @Override
public void onCreate() {
    super.onCreate();
    try {
        EventInput mockEventnew EventInput();
        Log.d("jni",mockEvent.eventInject());
    }catch (Exception e){
        e.printStackTrace();
    }
}  

And I push it to /system/app to make it be a system app which will listen the boot broadcast and start the service.But it runs with:

java.lang.UnsatisfiedLinkError: Couldn't load jni-input: findLibrary returned null

Solution

I resolved it myself. In compared with regular app,the nativelibrarydirectories of apk in /system/app are /vender/lib and / system/lib by default which are the search-path for loading .so file.So, It works well when I push my .so file in /system/lib.

Answered By – helloliu

Leave a Comment