Android Emulator Workaround

Here is a small tip if you are having trouble running the Android Emulator for code that calls native methods and getting an error message similar to this:

JNI WARNING: method declared to return 'Ljava/nio/ByteBuffer;' returned 'Ljava/nio/ReadWriteDirectByteBuffer;'
... ;.nativeAsBuffer ('Ljava/nio/ByteBuffer;' not found)

The simple workaround is to add the following to the onCreate method of your main activity:

ByteBuffer dummy = ByteBuffer.allocate(0); dummy = null;

This way the classloader is “forced” to load ByteBuffer. This is not needed when running on a device, only the emulator as it seems.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.