user693375
user693375

Reputation: 48

is JNI implemented differently on some devices?

I have a native app (2.2) that has been running without problem on my old Motorola Droid device (2.1). Recently i purchased a shiny new Sanyo Zio (2.2.1) but the same code that ran on the Droid gets the following runtime error:

04-05 12:43:34.006: WARN/dalvikvm(901): JNI WARNING: expected return type 'I'

and the code then aborts. I am trying to get a long variable from the Native side with the following call:

static jmethodID = java_getScore = env->GetStaticMethodID(javaClass, "native_getScore", "()J");

The JNI implementation works perfectly on my old Droid, but not on the newer Zio.

Is there something i have overlooked in my original implementation?

Thanks for you time.

Upvotes: 1

Views: 1298

Answers (3)

Elliott Hughes
Elliott Hughes

Reputation: 4665

No, JNI isn't implemented differently on any device I know of. But it changes from release to release (I know this, because I'm often the guy working on it). In particular, newer releases are likely to find more errors in your code. The best defense is to run your code with CheckJNI on the newest release: http://android-developers.blogspot.com/2011/07/debugging-android-jni-with-checkjni.html

In particular, newer releases will report a slightly better error message in your case, telling you what you called and what you should have called, and what method you were trying to call.

Upvotes: 0

white_gecko
white_gecko

Reputation: 5086

As you finally found out, (and I also just found out) there are different functions, to invoke Java methods from the native code. They are listed here: http://java.sun.com/docs/books/jni/html/functions.html#87060

Upvotes: 0

Chris Cashwell
Chris Cashwell

Reputation: 22899

JNI suffers from at least one major flaw in addition to the many lesser flaws: it is not platform/device nonspecific.

Another issue that make me hate JNI is that you can't access arbitrary functions in arbitrary DLLs. JNI requires you to write a glue layer in C/C++ in order to do whatever it is you intend to do natively.

So yes, in short, JNI implementation is different on every device.

Upvotes: 1

Related Questions