Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-05

Android JNI failing in Galaxy S4

20 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Felipe Monteiro de Carvalho

Hello,

I know that some other people here are developing Android JNI apps.

For me it has worked perfectly so far, but as we just got a Galaxy S4 in the office 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 code is being executed.

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';
    ;),

And is correct in RegisterNative:

  // 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;

My only idea at the moment is to do the static export too... maybe that will work, lets see.

Felipe Monteiro de Carvalho

Reply by email

Felipe Monteiro de Carvalho
to Felipe Monteiro de Carvalho

Oh, forget it. Someone answered in android-ndk group: I had a typo in another JNI routine which caused the problem.

It seams that the new Android checks all JNI ones checked the routines only when they were utilized, so would only crash when it was utilized.

Felipe Monteiro de Carvalho

Reply by email

Sven Barth
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 7 lines
Oh, forget it. Someone answered in android-ndk group: I had a typo in another JNI routine which caused the problem. It seams that the new Android checks all JNI routines at startup. Older ones checked the routines only when they were utilized, so would only crash when it was utilized.

Now one can argue which variant of the two is the better...

Regards,
Sven

Reply by email

Unknown author
to Felipe Monteiro de Carvalho: Oh, forget it. Someone answered in android-ndk group: I had a typo in another JNI routine…

Are you saying that you are writing JNI routines in Pascal for android?

If so, can you post some of the things like the pascal header files you use to allow for the creation of the .so files
so that Java can call into pascal across the JNI interface.

I have 2 projects that I need Pascal talking across the JNI interface. 1 for Mac OSX where I need pascal to call a JNI library and another Android where I need Java to call freepascal library (NDK)

Thanks for any information you can share,

md

Felipe Monteiro de Carvalho wrote 7 lines
Oh, forget it. Someone answered in android-ndk group: I had a typo in another JNI routine which caused the problem. It seams that the new Android checks all JNI routines at startup. Older ones checked the routines only when they were utilized, so would only crash when it was utilized.

Reply by email

Torsten Bonde Christiansen
to Unknown author
Show quoted text 12 lines
Are you saying that you are writing JNI routines in Pascal for android? If so, can you post some of the things like the pascal header files you use to allow for the creation of the .so files so that Java can call into pascal across the JNI interface. I have 2 projects that I need Pascal talking across the JNI interface. 1 for Mac OSX where I need pascal to call a JNI library and another Android where I need Java to call freepascal library (NDK) Thanks for any information you can share,

+1 from me, I would like that too.

Thanks,
Torsten Bonde Christiansen.

Reply by email

Felipe Monteiro de Carvalho
to Unknown author: Are you saying that you are writing JNI routines in Pascal for android? If so, can you…

Hello,

Are you saying that you are writing JNI routines in Pascal for android?

Yes. And luckly it works in all devices =) I was a bit scared that I might hit a wierd problem here involving code generation or whatever, but ... just a normal typo in my program.

If so, can you post some of the things like the pascal header files you use to allow for the creation of the .so files so that Java can call into pascal across the JNI interface.

See here:

http://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/bindings/android-ndk/

The file jni.pas is what you are looking for. The rest are Android NDK headers. I think that it should work for any Java platform.

In the folder "examples" there, there is a full Android JNI example.

In lazarus/lcl/interfaces/customdrawn/* there is also a lot of JNI code for Android which can be utilized as examples to learn how to use JNI.

Felipe Monteiro de Carvalho

Reply by email

Unknown author
to Felipe Monteiro de Carvalho

You sir,

Are a good man.

Thx for the link.

Watch out when the Intel mobile processors come along, I doubt they will be ARM 7 compatible.
But they may be x86!

md

Felipe Monteiro de Carvalho wrote 24 lines
Hello, On Wed, May 22, 2013 at 1:50 PM, wrote: > Are you saying that you are writing JNI routines in Pascal for android? Yes. And luckly it works in all devices =) I was a bit scared that I might hit a wierd problem here involving code generation or whatever, but ... just a normal typo in my program. > If so, can you post some of the things like the pascal header files you use > to allow for the creation of the .so files > so that Java can call into pascal across the JNI interface. See here: http://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/bindings/android-ndk/ The file jni.pas is what you are looking for. The rest are Android NDK headers. I think that it should work for any Java platform. In the folder "examples" there, there is a full Android JNI example. In lazarus/lcl/interfaces/customdrawn/* there is also a lot of JNI code for Android which can be utilized as examples to learn how to use JNI.

Reply by email

Unknown author
to Felipe Monteiro de Carvalho: Yes. And luckly it works in all devices =) I was a bit scared that I might hit a wierd…

Felipe:

Any comments on how you would mix C and pascal into the same binary for JNI/Android?

I have some encryption routines in C that I need to link to Pascal and then get called by Java.

md

Felipe Monteiro de Carvalho wrote 24 lines
Hello, On Wed, May 22, 2013 at 1:50 PM, wrote: > Are you saying that you are writing JNI routines in Pascal for android? Yes. And luckly it works in all devices =) I was a bit scared that I might hit a wierd problem here involving code generation or whatever, but ... just a normal typo in my program. > If so, can you post some of the things like the pascal header files you use > to allow for the creation of the .so files > so that Java can call into pascal across the JNI interface. See here: http://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/bindings/android-ndk/ The file jni.pas is what you are looking for. The rest are Android NDK headers. I think that it should work for any Java platform. In the folder "examples" there, there is a full Android JNI example. In lazarus/lcl/interfaces/customdrawn/* there is also a lot of JNI code for Android which can be utilized as examples to learn how to use JNI.

Reply by email

Felipe Monteiro de Carvalho
to Unknown author
Watch out when the Intel mobile processors come along, I doubt they will be ARM 7 compatible. But they may be x86!

That's not problem. If we have x86 too, then instead of doing 2 clicks to build the project, I'll have to do 4 clicks. 1 to build for arm, 1 to change the build mode, 1 to build for x86 and 1 to build both apks

Doesn't change much to me =)

Any comments on how you would mix C and pascal into the same binary for JNI/Android?

Maybe in the same way that is done in desktops?
via {$L objectfile.o} + headers with the directive external

Something like:

uses ctypes;
function something_from_c(params: cint): cint; cdecl; external;

I think it is $L ... I haven't utilized this feature in a long time.

Your c code needs to be compiled for arm-android of course.

Felipe Monteiro de Carvalho

Reply by email

Unknown author
to Torsten Bonde Christiansen: +1 from me, I would like that too. Torsten Bonde Christiansen.

Anybody successful putting Freepascal 2.6.2 / Lazarus 1.0.8 on Fedora 18.

It seems like Fedora 18 has symbolic links which point /bin and /sbin to /usr/bin and /usr/sbin respectively.

/bin -> /usr/bin
/sbin -> /usr/sbin

Then the compiler chokes an error about "You must have an old compiler" because it can find fpc located in 2 different locations.

But what the compiler/lazarus does not know is that they are pointed to the same compiler using 2 different routes, one via the hard file system and the other using a symbolic link.

Ideas on how to set up the compiler / lazarus for Fedora 18?

(I am not certain about Fedora 15,16,17 since I only used Fedora 14 and Fedora 18.

md

Reply by email

Unknown author
to Mattias Gaertner

Yes, you may have built the rpms on the platform, but where was the ultimate destination for the executables
after you RAN the RPM to install the program?

It seems that Fedora 18 unified /bin -> /usr->bin using symbolic links and so the compiler is not ready to run
on a system where it installs the binaries to /usr/bin.

So what I am saying for the lazarus/freepascal binary package installers is that they need to consider having
some option of changing where the installed binaries go that is different than /usr/bin. Maybe /usr/local/bin?

md

Mattias Gaertner wrote 12 lines
> "" hat am 22. Mai 2013 um 17:18 > geschrieben: > > > Anybody successful putting Freepascal 2.6.2 / Lazarus 1.0.8 on Fedora 18. I built successfully the 64bit rpms on a FC 18 64bit and had no such problems. Mattias _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Unknown author
to Reimar Grabowski

Oops,

Looks like there is an internal list coded identifier that links the thread of emails together.

The moral of the story is to create a completely new email to start another discussion thread
and stay away from "Reply" button for convenience.

Sorry about the hijacking, it was not intended.

md

Reimar Grabowski wrote 8 lines
Is it just me or is this Fedora stuff hijacking the Android Galaxy S4 thread? If it is not a problem of my mail client, PLEASE stop this sh!t. R. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Mark Morgan Lloyd
to Unknown author
Oops, Looks like there is an internal list coded identifier that links the thread of emails together.

Yes, that's been in email since the earliest days- 30 years or so. Look:

-----8<-----
References:

----->8-----

That is totally distinct from the subject line, which is really there only as a summary and which can be changed without breaking an existing thread.

My understanding is that MS mail clients have not been very good at honouring this over the years, but "standards compliant" software always has. The fact that a lot of people make this mistake in ignorance is really no excuse.

SO EVERYBODY, PLEASE:

The moral of the story is to create a completely new email to start another discussion thread and stay away from "Reply" button for convenience.

YES, YES, YES, YES, YES!!!

Ask yourself: would you walk into a party with a friend, find two people in earnest conversation, stand next to them talking loudly and expect them to be happy about it?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
Jonas Maebe wrote 6 lines
I understand this is well-intended, but please don't overdo it. The person apologised and acknowledged what his mistake was. Adding a long extra message on this topic does not really add anything useful to the discussion and does not help with creating a friendly atmosphere either. In general comments about such issues, if posted to the list, should only be made by the moderator in any case.

My apologies, but I was trying to confirm that there was, in fact a header and to show that it had been part of the email standards for a very long time. It's nothing new, it's not specific to mailing list managers, and it's definitely not specific to this mailing list.

I was definitely not trying to "get at" the poster who had inadvertently triggered somebody else's outrage, particularly since he had realised and pointed out what he'd done wrong. However I find the number of complaints I see about this behaviour irritating- it's difficult enough to keep abreast of things as it is.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email