Android - How to enable CheckJni for NDK development?

vamsibm picture vamsibm · Nov 30, 2009 · Viewed 13.4k times · Source

Can someone please tell me if I'm missing something here? I am trying the following commands in shell.

$ ./adb shell stop
$ ./adb shell setprop dalvik.vm.checkjni true
$ ./adb shell start

But Logcat always shows "CheckJNI is OFF" when I install the apk onto the device.
Is there something else in eclipse that I need to do to enable the XCheck:Jni flag?

Thanks for any help BD

Answer

Playful Curiosity picture Playful Curiosity · Sep 21, 2012

There is four different cases, one for rooted device, one for emulator, one for regular device and one for rooted or regular device.


On rooted device I was able to get it working so:

In adb:

adb shell

In launched after this shell:

su
stop
setprop dalvik.vm.checkjni true
start

After this device was rebooted and at boot I see log message:

CheckJNI is ON



For other cases see some theory from official docs:

There are several ways to enable CheckJNI.

If you’re using the emulator, CheckJNI is on by default.

If you have a rooted device, you can use the following sequence of commands to restart the runtime with CheckJNI enabled:

adb shell stop
adb shell setprop dalvik.vm.checkjni true
adb shell start

In either of these cases, you’ll see something like this in your logcat output when the runtime starts:

D AndroidRuntime: CheckJNI is ON

If you have a regular device, you can use the following command:

adb shell setprop debug.checkjni 1

This won’t affect already-running apps, but any app launched from that point on will have CheckJNI enabled. (Change the property to any other value or simply rebooting will disable CheckJNI again.) In this case, you’ll see something like this in your logcat output the next time an app starts:

D Late-enabling CheckJNI

You can also set the android:debuggable attribute in your application's manifest to turn on CheckJNI just for your app. Note that the Android build tools will do this automatically for certain build types.