What JNI version should JNI_OnLoad() return for Android Eclair?

9,935 views
Skip to first unread message

theactiveactor

unread,
Jul 15, 2010, 4:26:27 PM7/15/10
to android-ndk
I'm running Android Eclair (don't know if platform version matters)
and currently my JNI_OnLoad() is causing the dynamic link error:
"JNI_OnLoad returned bad version". What should be the right version
and where can I find this info for other versions of the Android
platform?

Onur Cinar

unread,
Jul 15, 2010, 4:50:15 PM7/15/10
to andro...@googlegroups.com

Hi,

Here are the supported versions from the jni.h file:

#define JNI_VERSION_1_1 0x00010001
#define JNI_VERSION_1_2 0x00010002
#define JNI_VERSION_1_4 0x00010004
#define JNI_VERSION_1_6 0x00010006

Which version are you returning from JNI_OnLoad()?   Also are you using anything specific to a JNI version?

Regards,

-onur


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


---
www.zdo.com

theactiveactor

unread,
Jul 16, 2010, 4:45:43 PM7/16/10
to android-ndk
My mistake, I was returning 0. How do I know which version of JNI I
need? I am not aware of any version-specific features I'm using, so is
it safer to go with an older version?

On Jul 15, 4:50 pm, Onur Cinar <onur.ci...@gmail.com> wrote:
> Hi,
>
> Here are the supported versions from the jni.h file:
>
> #define JNI_VERSION_1_1 0x00010001
> #define JNI_VERSION_1_2 0x00010002
> #define JNI_VERSION_1_4 0x00010004
> #define JNI_VERSION_1_6 0x00010006
>
> Which version are you returning from JNI_OnLoad()?   Also are you using
> anything specific to a JNI version?
>
> Regards,
>
> -onur
>
> On Thu, Jul 15, 2010 at 1:26 PM, theactiveactor <theactiveac...@gmail.com>wrote:
>
>
>
>
>
> > I'm running Android Eclair (don't know if platform version matters)
> > and currently my JNI_OnLoad() is causing the dynamic link error:
> > "JNI_OnLoad returned bad version".  What should be the right version
> > and where can I find this info for other versions of the Android
> > platform?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>
> > .

Onur Cinar

unread,
Jul 16, 2010, 5:24:05 PM7/16/10
to andro...@googlegroups.com

Hi,

If you are not doing anything within the JNI_OnLoad other than returning the JNI version number, it is always safer to simply not implement that function, so that JVM can fall back to the defaults.  However, if you are doing anything in that, than unless you are using anything specific to a certain version of JNI, it should be fine to return JNI_VERSION_1_1.

Regards,

-onur

To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


---
www.zdo.com

theactiveactor

unread,
Jul 16, 2010, 6:23:26 PM7/16/10
to android-ndk
I'm only using JNI_OnLoad() to make a global cache of the JavaVM
reference, so JNI_VERSION_1_1 should be fine.

Thanks!

On Jul 16, 5:24 pm, Onur Cinar <onur.ci...@gmail.com> wrote:
> Hi,
>
> If you are not doing anything within the JNI_OnLoad other than returning the
> JNI version number, it is always safer to simply not implement that
> function, so that JVM can fall back to the defaults.  However, if you are
> doing anything in that, than unless you are using anything specific to a
> certain version of JNI, it should be fine to return JNI_VERSION_1_1.
>
> Regards,
>
> -onur
>

Onur Cinar

unread,
Jul 16, 2010, 6:36:21 PM7/16/10
to andro...@googlegroups.com

Hi,

I was just looking at the Dalvik code:

http://android.git.kernel.org/?p=platform/dalvik.git;a=blob_plain;f=vm/Native.c;hb=HEAD

Looks like it is only using the version number to reject libraries requesting versions other than 1.2, 1.4, 1.6?

 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4 && version != JNI_VERSION_1_6)
 {
     LOGW("JNI_OnLoad returned bad version (%d) in %s %p\n", version, pathName, classLoader);
     ...


So you may want to return JNI_VERSION_1_2.

Regards,

-onur


To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


---
www.zdo.com

Doug Schaefer

unread,
Jul 16, 2010, 6:46:20 PM7/16/10
to andro...@googlegroups.com
According to the JNI spec, you're supposed to return the version of
JNIEnv that your library supports. It should be safe to use the latest
version in the jni.h file. I assume the JNIEnv we have there is 1.6.

fadden

unread,
Jul 16, 2010, 7:27:37 PM7/16/10
to android-ndk
On Jul 16, 3:46 pm, Doug Schaefer <cdtd...@gmail.com> wrote:
> According to the JNI spec, you're supposed to return the version of
> JNIEnv that your library supports. It should be safe to use the latest
> version in the jni.h file. I assume the JNIEnv we have there is 1.6.

JNI_OnLoad wasn't supported until 1.2, so clearly the library expects
a version of JNI newer than 1.1. :-)

Since everyone is presumably coding against the current version of the
JNI spec, using JNI_VERSION_1_6 makes the most sense. The only reason
to use anything else would be if the code needs to run against some
other VM that only supports an older version of JNI. In theory Dalvik
should provide different behavior for certain calls when a library
requests 1.1 behavior (e.g. preventing you from using several of
them), but in practice this isn't implemented.

See also:
http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/technotes/guides/jni/spec/invocation.html#JNI_OnLoad
Reply all
Reply to author
Forward
0 new messages