App with JNI stopped working in 4.2

595 views
Skip to first unread message

Felipe Monteiro de Carvalho

unread,
May 21, 2013, 12:01:25 PM5/21/13
to andro...@googlegroups.com
Hello,

I have an application with a Java part for the UI which connects itself to a JNI library written in Pascal (Free Pascal 2.7 cross-compiler for ARM). My target is API level 8. Everything has gone fine for years in this setup in dozens and dozens of different phones. 

But today we just got a Galaxy S4 in the office, so I thought of testing my app there and boom =( It crashes at the startup:

I/True Democracy( 8624): Trying to load libtruedemocracy.so
D/dalvikvm( 8624): Trying to load lib
/data/app-lib/com.felipe.truedemocracy-1/libtruedemocracy.so
0x421fadc8
W/libc ( 8624): WARNING: generic atexit() called from legacy shared library
D/dalvikvm( 8624): Added shared lib
/data/app-lib/com.felipe.truedemocracy-1/libtruedemocracy.so
0x421fadc8
I/truedemocracy( 8624): JNI_OnLoad called
I/truedemocracy( 8624): Reading our Activity Class
E/dalvikvm( 8624): ERROR: couldn't find native method
E/dalvikvm( 8624): Requested:
Lcom/felipe/truedemocracy/TrueDemocracy;.GetHistoricalInflationCount:()I
F/truedemocracy( 8624): javaEnvRef^.RegisterNatives failed
I/truedemocracy( 8624): JNI_OnLoad finished
D/qdmemalloc( 217): ion: unmap_buffer base:0x0 size:8355840 offset:0 fd:49
D/qdmemalloc( 217): ion: unmap_buffer base:0x0 size:4096 offset:0 fd:78
D/qdmemalloc( 217): ion: unmap_buffer base:0x0 size:8355840 offset:0 fd:66
D/qdmemalloc( 217): ion: unmap_buffer base:0x0 size:4096 offset:0 fd:67
W/dalvikvm( 8624): No implementation found for native
Lcom/felipe/truedemocracy/TrueDemocracy;.Translations_TranslateToISO639_2_Code:(Ljava/lang/String;Ljava/lang/String;)V
D/AndroidRuntime( 8624): Shutting down VM
W/dalvikvm( 8624): threadid=1: thread exiting with uncaught exception
(group=0x410b8ac8)
D/Sensorhubs( 228): readContextData: 1, 1, 14, 1
D/SensorHubManager( 724): onGetSensorHubDataLocked: library = 1, 1, 14, 1
D/CAE ( 724): onGetSensorHubData(SensorHubParserProvider.java:66)
- onGetSensorHubData Event [event buffer len :4]
I/CAE ( 724): parse(SensorHubParserProvider.java:129) - buffer size = 4
I/CAE ( 724): parse(SensorHubParserProvider.java:140) - 1, 1, 14, 1,
D/qdoverlay( 217): Unset pipe=VG0 dpy=0; Unset pipe=VG1 dpy=0; Unset
pipe=RGB1 dpy=0;
D/CAE ( 724): display(ContextProvider.java:430) -
================= FLIP_COVER_ACTION =================
V/WindowManager( 724): Window{42b3a138 u0
Keyguard}mOrientationRequetedFromKeyguard=false
E/AndroidRuntime( 8624): FATAL EXCEPTION: main
E/AndroidRuntime( 8624): java.lang.UnsatisfiedLinkError: Native method
not found: com.felipe.truedemocracy.TrueDemocracy.Translations_TranslateToISO639_2_Code:(Ljava/lang/String;Ljava/lang/String;)V
E/AndroidRuntime( 8624): at
com.felipe.truedemocracy.TrueDemocracy.Translations_TranslateToISO639_2_Code(Native
Method)
E/AndroidRuntime( 8624): at
com.felipe.truedemocracy.TrueDemocracy.onCreate(TrueDemocracy.java:632)
E/AndroidRuntime( 8624): at
android.app.Activity.performCreate(Activity.java:5250)
E/AndroidRuntime( 8624): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
E/AndroidRuntime( 8624): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
E/AndroidRuntime( 8624): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296)
E/AndroidRuntime( 8624): at
android.app.ActivityThread.access$700(ActivityThread.java:151)
E/AndroidRuntime( 8624): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
E/AndroidRuntime( 8624): at
android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 8624): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 8624): at
android.app.ActivityThread.main(ActivityThread.java:5293)
E/AndroidRuntime( 8624): at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 8624): at
java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 8624): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
E/AndroidRuntime( 8624): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
E/AndroidRuntime( 8624): at dalvik.system.NativeStart.main(Native Method)

Any ideas?

I am not doing anything unusual, and exact same APK works fine in HTC
Wildfire, Xperia Mini, Galaxy Nexus, etc, etc.

=(

it runs JNI_onCreate to the end, so at least the Pascal code is being executed ok.

The routine that it complains about is declared correctly:

procedure Java_com_felipe_truedemocracy_TrueDemocracy_Translations_TranslateToISO639_2_Code(
env:PJNIEnv; this:jobject; AISOCode, ACountry: jstring); cdecl;

And is correct in the structure:

(name:'Translations_TranslateToISO639_2_Code';
signature:'(Ljava/lang/String;Ljava/lang/String;)V';
fnPtr:@Java_com_felipe_truedemocracy_TrueDemocracy_Translations_TranslateToISO639_2_Code;),

 And is correct in RegisterNative inside JNI_onCreate:

// Register Pascal exported calls
if javaEnvRef^^.RegisterNatives(javaEnvRef, javaActivityClass,
@NativeMethods[0],length(NativeMethods))<0 then
begin
__android_log_write(ANDROID_LOG_FATAL, 'truedemocracy',
'javaEnvRef^.RegisterNatives failed');
end;

any ideas?

Why does it say that my library is a legacy one?

thanks,

Felipe Monteiro de Carvalho

a1

unread,
May 21, 2013, 2:35:22 PM5/21/13
to andro...@googlegroups.com

I/truedemocracy( 8624): JNI_OnLoad called
I/truedemocracy( 8624): Reading our Activity Class
E/dalvikvm( 8624): ERROR: couldn't find native method
E/dalvikvm( 8624): Requested:
Lcom/felipe/truedemocracy/TrueDemocracy;.GetHistoricalInflationCount:()I
F/truedemocracy( 8624): javaEnvRef^.RegisterNatives failed
 
This looks like a culprit - RegisterNatives failed so of course natives are not bound. As you can see there is an error complaining about GetHistoricalInflationCount method, if you check dalvik JNI implementation (https://android.googlesource.com/platform/dalvik/+/master/vm/Jni.cpp) this error is print if one of method passed to RegisterNatives is not found, so the problem is with GetHistoricalInflationCount not with TranslateToISO639 method.

--
Bart

Felipe Monteiro de Carvalho

unread,
May 21, 2013, 2:50:46 PM5/21/13
to andro...@googlegroups.com
Oh, great hint =) Indeed there was an error there! I have over 60 JNI methods so it seams I made a copy+paste mistake here:

(name:'GetHistoricalInfl'; signature:'()I'; fnPtr:@Java_com_felipe_truedemocracy_TrueDemocracy_Model_GetHistoricalInflationCount;),

just fixing the name to the proper one, 'Model_GetHistoricalInflationCount' will probably fix it then.

Will check tomorrow if it works!

=)

I think that in older versions it would crash only in the first call to the JNI method.

Felipe Monteiro de Carvalho

Felipe Monteiro de Carvalho

unread,
May 23, 2013, 7:29:47 AM5/23/13
to andro...@googlegroups.com
For future reference: Yes, indeed it was a typo on that routine declaration in the structure passed to RegisterNatives.
Reply all
Reply to author
Forward
0 new messages