Sign in Join

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

Mailing lists / fpc-pascal / 2013-07

Android and cwstring

11 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Torsten Bonde Christiansen

Hi,

I'm trying to create a library for use in an android application, but i'm having a hard time getting it to work correctly.

More specifically i cannot get the library to use the "cwstring" unit. Below you see a working example of a library that works fine (the log entry is generated) when cwstring i commented out, but when included the android application just hangs on the message:

07-31 16:52:16.284: D/dalvikvm(338): Trying to load lib /data/data/dk.epidata.epidatatestproject/lib/libepitest.so 0x45f3e268

The error is most likely mine, my experience with android programming and libraries are limited, but I fail to see what I am doing wrong in this case.

Just for record i use:
ppcrossarm -i
Free Pascal Compiler version 2.7.1

Compiler Date : 2013/07/25
Compiler CPU Target: arm

Settings for android in .fpc.cfg:
-CfVFPV3

#ifdef cpuarm
-Xd
-FD/home/torsten/AndroidDev/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin -Fl/home/torsten/AndroidDev/android-ndk-r8e/platforms/android-14/arch-arm/usr/lib -XParm-linux-androideabi-
#endif

Regards,
Torsten B. Christiansen.

====== library code ======

library project1;
{$mode objfpc}{$H+}

uses
jni, // jni from packages/jni/src/jni.pas
cmem, // includin cmem makes no difference
cwstring // including cwstring make the library halt on load... :(

   ;
const
   ANDROID_LOG_INFO=4;
function LOGI(prio:longint;tag,text:pchar):longint; cdecl; varargs;
external 'liblog.so' name '__android_log_print';
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
begin
   result:=JNI_VERSION_1_6;
end;
exports
   JNI_OnLoad;
begin
   LOGI(ANDROID_LOG_INFO, 'libepitest.so', 'Init Library');
end.

Reply by email

Felipe Monteiro de Carvalho
to Torsten Bonde Christiansen
Torsten Bonde Christiansen wrote
More specifically i cannot get the library to use the "cwstring" unit. Below you see a working example of a library that works fine (the log entry is generated) when cwstring i commented out, but when included the android application just hangs on the message:

Doesn't cwstring link to the iconv library? If yes, then I guess you can give up on using it on Android. There is no iconv available in Android for 3rd party applications. The list of available libraries is very small, I described it here for API level 8 which is what I usually set as my minimum requisite:
http://wiki.lazarus.freepascal.org/Custom_Drawn_Interface/Android#NDK_Libraries_available_in_Android_2.2_.28API_level_8.29

Anyway, I wrote a 100% Pascal widestring manager implementation which works in Android, it is available in the Lazarus source tree, here: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/components/lazutils/paswstring.pas?view=markup&revision=41389&root=lazarus

You can copy it to your project and use it.

Felipe Monteiro de Carvalho

Reply by email

Sven Barth
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 13 lines
On Wed, Jul 31, 2013 at 3:11 PM, Torsten Bonde Christiansen wrote: > More specifically i cannot get the library to use the "cwstring" unit. Below > you see a working example of a library that works fine (the log entry is > generated) when cwstring i commented out, but when included the android > application just hangs on the message: Doesn't cwstring link to the iconv library? If yes, then I guess you can give up on using it on Android. There is no iconv available in Android for 3rd party applications. The list of available libraries is very small, I described it here for API level 8 which is what I usually set as my minimum requisite: http://wiki.lazarus.freepascal.org/Custom_Drawn_Interface/Android#NDK_Libraries_available_in_Android_2.2_.28API_level_8.29

The cwstring of Android uses the ICU library libicuuc.so.

Show quoted text 6 lines
Anyway, I wrote a 100% Pascal widestring manager implementation which works in Android, it is available in the Lazarus source tree, here: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/components/lazutils/paswstring.pas?view=markup&revision=41389&root=lazarus You can copy it to your project and use it.

FPC 2.7.1 also contains a Pascal only widestring manager called fpwidestring. You'll need to add additional units for the required codepages though. They are called collation_LANGUAGE (e.g. collation_de).

Regards,
Sven

Reply by email

Felipe Monteiro de Carvalho
to Sven Barth
Sven Barth wrote
The cwstring of Android uses the ICU library libicuuc.so.

Is this available in the NDK for one of the higher API levels? It is not in the list for API level 8.

Felipe Monteiro de Carvalho

Reply by email

Sven Barth
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 6 lines
On Wed, Jul 31, 2013 at 8:51 PM, Sven Barth wrote: > The cwstring of Android uses the ICU library libicuuc.so. Is this available in the NDK for one of the higher API levels? It is not in the list for API level 8.

I don't know, I have merely quoted the commit message for when cwstring was changed from a stub to a more complete implementation for Android. If it is truly not available in lower API levels then I'd suggest to use fpwidestring anyway...

Regards,
Sven

Reply by email

Torsten Bonde Christiansen
to Sven Barth
Sven Barth wrote 13 lines
On 31.07.2013 20:55, Felipe Monteiro de Carvalho wrote: > On Wed, Jul 31, 2013 at 8:51 PM, Sven Barth > wrote: >> The cwstring of Android uses the ICU library libicuuc.so. > > Is this available in the NDK for one of the higher API levels? It is > not in the list for API level 8. > I don't know, I have merely quoted the commit message for when cwstring was changed from a stub to a more complete implementation for Android. If it is truly not available in lower API levels then I'd suggest to use fpwidestring anyway...

I did some research before i sent the mail and found the libucuuc.so using adb shell into an emulator.

I will take a look at the fpwidestring and paswstring.

Thanks for the help.

REgards,
Torsten.

Reply by email

Felipe Monteiro de Carvalho
to Torsten Bonde Christiansen
Torsten Bonde Christiansen wrote
I did some research before i sent the mail and found the libucuuc.so using adb shell into an emulator.

That's a common mistake. Android is a full Linux inside, so of course there are tons of native libraries available inside. But they are not guaranteed to be there, they are not guaranteed to work as expected in all devices, etc. One should never use libraries outside the list of available NDK libraries. I'm not saying it won't work, it might work, but the official position of Google developers is that they should not be used.

Felipe Monteiro de Carvalho

Reply by email

Torsten Bonde Christiansen
to Sven Barth: I don't know, I have merely quoted the commit message for when cwstring was changed from…
Sven Barth wrote 14 lines
On 31.07.2013 20:55, Felipe Monteiro de Carvalho wrote: > On Wed, Jul 31, 2013 at 8:51 PM, Sven Barth > wrote: >> The cwstring of Android uses the ICU library libicuuc.so. > > Is this available in the NDK for one of the higher API levels? It is > not in the list for API level 8. > I don't know, I have merely quoted the commit message for when cwstring was changed from a stub to a more complete implementation for Android. If it is truly not available in lower API levels then I'd suggest to use fpwidestring anyway...

hmmm.... i can't get fpwidestring to work, it seem that it is not compiled during a normal compiler build. The same goes for all of the collation units.

Should i add and special defines to get them compiled or is it a bug in the makefile?

Regards,
Torsten.

Reply by email

Sven Barth
to Torsten Bonde Christiansen
Torsten Bonde Christiansen wrote 21 lines
On 2013-07-31 20:57, Sven Barth wrote: > On 31.07.2013 20:55, Felipe Monteiro de Carvalho wrote: >> On Wed, Jul 31, 2013 at 8:51 PM, Sven Barth >> wrote: >>> The cwstring of Android uses the ICU library libicuuc.so. >> >> Is this available in the NDK for one of the higher API levels? It is >> not in the list for API level 8. >> > > I don't know, I have merely quoted the commit message for when > cwstring was changed from a stub to a more complete implementation for > Android. If it is truly not available in lower API levels then I'd > suggest to use fpwidestring anyway... > hmmm.... i can't get fpwidestring to work, it seem that it is not compiled during a normal compiler build. The same goes for all of the collation units. Should i add and special defines to get them compiled or is it a bug in the makefile?

How exactly did you compile?

As described in the wiki with "make crossall OS_TARGET=android CPU_TARGET=arm ..." in the top level directory? In that case it should be compiled and a fpwidestring.ppu should be located in the $fpcsrc/rtl/units/arm-android directory.

Regards,
Sven

Reply by email

Torsten Bonde Christiansen
to Sven Barth
Sven Barth wrote 30 lines
On 01.08.2013 20:43, Torsten Bonde Christiansen wrote: > On 2013-07-31 20:57, Sven Barth wrote: >> On 31.07.2013 20:55, Felipe Monteiro de Carvalho wrote: >>> On Wed, Jul 31, 2013 at 8:51 PM, Sven Barth >>> wrote: >>>> The cwstring of Android uses the ICU library libicuuc.so. >>> >>> Is this available in the NDK for one of the higher API levels? It is >>> not in the list for API level 8. >>> >> >> I don't know, I have merely quoted the commit message for when >> cwstring was changed from a stub to a more complete implementation for >> Android. If it is truly not available in lower API levels then I'd >> suggest to use fpwidestring anyway... >> > hmmm.... i can't get fpwidestring to work, it seem that it is not > compiled during a normal compiler build. The same goes for all of the > collation units. > > Should i add and special defines to get them compiled or is it a bug in > the makefile? How exactly did you compile? As described in the wiki with "make crossall OS_TARGET=android CPU_TARGET=arm ..." in the top level directory? In that case it should be compiled and a fpwidestring.ppu should be located in the $fpcsrc/rtl/units/arm-android directory. ̈́

I did that, but I also included a "crossinstall" which installed the units to somewhere else in my home dir.

However now that i compare the $fpcsrc/rtl/units/arm-android with $install_dir/rtl/units/arm-android some of the files are missing - this includes the fpwidestring and collation files... strange?

Regards,
Torsten.

Reply by email

Jonas Maebe
to Torsten Bonde Christiansen
Torsten Bonde Christiansen wrote 8 lines
On 2013-08-01 21:58, Sven Barth wrote: > How exactly did you compile? > > As described in the wiki with "make crossall OS_TARGET=android CPU_TARGET=arm ..." in the top level directory? In that case it should be compiled and a fpwidestring.ppu should be located in the $fpcsrc/rtl/units/arm-android directory. > ̈́ I did that, but I also included a "crossinstall" which installed the units to somewhere else in my home dir. However now that i compare the $fpcsrc/rtl/units/arm-android with $install_dir/rtl/units/arm-android some of the files are missing - this includes the fpwidestring and collation files... strange?

They're probably missing as implicit units in the makefile. However, even if you get them to install, they will probably crash unless the patch at http://bugs.freepascal.org/view.php?id=24158 is applied.

Jonas

Reply by email