First,I use NDK in the MainActivity,it works fine.:
public class MainActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
EventInput eventInput=new 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 mockEvent=new 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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.