android share library with classes unit

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

android share library with classes unit

herux
I managed to compile and run the library for android on emulator, which I compile the project just a libhellojni.so

compile using paramater like this

ppcarm -Scghi -O1 -Parm -gl -b -B -XX -Xc -XD -CpARMv6 -CfSOFT -dandroid  -vewnhi -l -XParm-linux- -Fi/home/herux/workspace/hellojni/jni/lib/arm-linux/ -Fu. -FUlib/arm-linux/ -o../libs/armeabi/libhellojni.so -FD/usr/share/fpcsrc/binutils/  hellojni.lpr

on Kubuntu 10.04 x86_64

library code:

library hellojni;
{$ ifdef fpc}
  {$ mode delphi}
{$ endif}

uses
     JNI, log;

Java_com_herux_hellojni_MainActivity_Hellojni function (env: PJNIEnv; Thiz: jobject): jstring; cdecl;
begin
   result: = env ^. NewStringUTF (env, PChar ('Hello JNI from FreePascal ..'));
end;
exports
        Java_com_herux_hellojni_MainActivity_Hellojni name 'Java_com_herux_hellojni_MainActivity_Hellojni';
begin
end;

then I try to use classes unit or sysutils, the project succeeded in compiling, but the library did not loaded by the emulator. there is an error SIGSEGV

D/dalvikvm( 1082): Trying to load lib /data/data/com.herux.hellojni/lib/libhellojni.so 0x44e7ea48
I/DEBUG   (   31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (   31): Build fingerprint: 'generic/sdk/generic/:2.2/FRF91/43546:eng/test-keys'
I/DEBUG   (   31): pid: 1082, tid: 1082  >>> com.herux.hellojni <<<
I/DEBUG   (   31): signal 11 (SIGSEGV), fault addr 7eb67b08
I/DEBUG   (   31):  r0 7eb67b08  r1 7eb67b08  r2 00000000  r3 0000003d
I/DEBUG   (   31):  r4 00000006  r5 809aa4cc  r6 b001037c  r7 00000000
I/DEBUG   (   31):  r8 80813b00  r9 0000ccb0  10 4186b904  fp beb1986c
I/DEBUG   (   31):  ip beb19870  sp beb19818  lr 809ab5d4  pc 809ab56c  cpsr 60000010
I/DEBUG   (   31):          #00  pc 000ab56c  /data/data/com.herux.hellojni/lib/libhellojni.so
I/DEBUG   (   31):          #01  lr 809ab5d4  /data/data/com.herux.hellojni/lib/libhellojni.so
I/DEBUG   (   31):
I/DEBUG   (   31): code around pc:

if anyone has ever experienced it? or is it a bug?

thanks
-
Reply | Threaded
Open this post in threaded view
|

Re: android share library with classes unit

Dariusz Mazur
  W dniu 2011-04-12 11:56, herux pisze:

> I managed to compile and run the library for android on emulator,
> which I compile the project just a libhellojni.so compile using
> paramater like this ppcarm -Scghi -O1 -Parm -gl -b -B -XX -Xc -XD
> -CpARMv6 -CfSOFT -dandroid -vewnhi -l -XParm-linux-
> -Fi/home/herux/workspace/hellojni/jni/lib/arm-linux/ -Fu.
> -FUlib/arm-linux/ -o../libs/armeabi/libhellojni.so
> -FD/usr/share/fpcsrc/binutils/ hellojni.lpr on Kubuntu 10.04 x86_64
> library code: library hellojni; {$ ifdef fpc} {$ mode delphi} {$
> endif} uses JNI, log; Java_com_herux_hellojni_MainActivity_Hellojni
> function (env: PJNIEnv; Thiz: jobject): jstring; cdecl; begin result:
> = env ^. NewStringUTF (env, PChar ('Hello JNI from FreePascal ..'));
> end; exports Java_com_herux_hellojni_MainActivity_Hellojni name
> 'Java_com_herux_hellojni_MainActivity_Hellojni'; begin end; then I try
> to use classes unit or sysutils, the project succeeded in compiling,
> but the library did not loaded by the emulator. there is an error
> SIGSEGV D/dalvikvm( 1082): Trying to load lib
> /data/data/com.herux.hellojni/lib/libhellojni.so 0x44e7ea48 I/DEBUG (
> 31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
> I/DEBUG ( 31):

How You prepare crosscompiler
  did You use -dARMEL -CpARMv6

or problems with binutils





On Android each bug in linking is showing the same


   Darek




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: android share library with classes unit

herux
I use this binutils http://www.gnu.org/software/binutils/
using this command to build crosscompiler

make clean crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=/usr/share/fpcsrc/binutils/ OPT="-dFPC_ARMEL -O- -gl" CROSSOPT="-dANDROID -CpARMv6 -gl -CfSOFT -O-"

I may have to repeat it

thank u
-
Reply | Threaded
Open this post in threaded view
|

Re: android share library with classes unit

Felipe Monteiro de Carvalho
Have you done "Step 2" described here:

http://wiki.lazarus.freepascal.org/Android_Interface#Using_the_pre-compiled_compiler

?

I know that those instructions are different from what you are doing,
but Step 2 should apply anyway.

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: android share library with classes unit

Dariusz Mazur
In reply to this post by herux
> I use this binutils http://www.gnu.org/software/binutils/
> using this command to build crosscompiler
>
> make clean crossinstall CPU_TARGET=arm OS_TARGET=linux
> CROSSBINDIR=/usr/share/fpcsrc/binutils/ OPT="-dFPC_ARMEL -O- -gl"
> CROSSOPT="-dANDROID -CpARMv6 -gl -CfSOFT -O-"

CROSSOPT="-dANDROID -CpARMv6  -dFPC_ARMEL "


I've trace Your debug log.  Bug is on line  where library is loaded.
It seems be corrupted. I always had once more line with absent of dlopen

D/dalvikvm( 1082): Trying to load lib
/data/data/com.herux.hellojni/lib/libhellojni.so 0x44e7ea48

here something with "dlopen", I don't remember exactly.
^^^^^^^^^^^
I/DEBUG   (   31): *** *** *** *** *** *** *** *** *** *** *** *** *** ***
*** ***


Darek

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: android share library with classes unit

Thomas Schatzl
In reply to this post by herux
 Hi,

 On Tue, 12 Apr 2011 02:56:39 -0700 (PDT), herux wrote:

> I managed to compile and run the library for android on emulator,
> which I
> compile the project just a libhellojni.so
>
> compile using paramater like this
>
> ppcarm -Scghi -O1 -Parm -gl -b -B -XX -Xc -XD -CpARMv6 -CfSOFT
> -dandroid
> -vewnhi -l -XParm-linux-
> -Fi/home/herux/workspace/hellojni/jni/lib/arm-linux/ -Fu.
> -FUlib/arm-linux/
> -o../libs/armeabi/libhellojni.so -FD/usr/share/fpcsrc/binutils/
> hellojni.lpr
>
> [...]
>
> then I try to use classes unit or sysutils, the project succeeded in
> compiling, but the library did not loaded by the emulator. there is
> an error
> SIGSEGV

 Fyi, there is an unresolved issue with Android shared library
 initialization code which affects the use of the sysutils unit, see
 http://bugs.freepascal.org/view.php?id=18833 for more details.

 Thomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: android share library with classes unit

herux
My problem is resolved, I apply the patch contained in that link. reported by Dejan Boras.
then rebuild cross compiler with this:

make clean crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR="/usr/share/fpcsrc/binutils" OPT="-dFPC_ARMEL -O- -gl" CROSSOPT="-dANDROID -CpARMv5 -gl -CfSOFT -O-"

now it's work. libhellojni.so loaded succesfully.

thanks

herux
-
Reply | Threaded
Open this post in threaded view
|

Re: android share library with classes unit

Felipe Monteiro de Carvalho
Forwarding to the mailling list:

On Thu, Apr 14, 2011 at 4:09 AM, heru susanto <[hidden email]> wrote:

> I've done the second step
> here :
> #!/bin/sh
> /usr/local/bin/arm-linux-as_org -march=armv6 -meabi=5 -mfloat-abi=softfp
> -mfpu=vfp3 $@
> my problem have been solved. my next problem is dynamic linking.
> thank you
> herux
>
>
> On Wed, Apr 13, 2011 at 3:29 PM, Felipe Monteiro de Carvalho
> <[hidden email]> wrote:
>>
>> Have you done "Step 2" described here:
>>
>>
>> http://wiki.lazarus.freepascal.org/Android_Interface#Using_the_pre-compiled_compiler
>>
>> ?
>>
>> I know that those instructions are different from what you are doing,
>> but Step 2 should apply anyway.
>>
>> --
>> Felipe Monteiro de Carvalho
>
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal