Recent

Author Topic: Did anyone try "fpc-3.0.2.i386-win32.cross.android.exe" under windows?  (Read 10822 times)

chenyuchih

  • Jr. Member
  • **
  • Posts: 81
Hi all,

Recently I installed "lazarus-1.6.4-fpc-3.0.2-win32.exe" from Lazarus sourceforge and downloaded the precompiled cross-compiling package "fpc-3.0.2.i386-win32.cross.android.exe" from FPC sourceforge page.
I specified the FPC directory as "C:\lazarus\fpc\3.0.2" and set android ndk path correctly during installation. I took a shared object project for test. It compiled smoothly without any error, but all functions cannot be called via JNI (JUST CRASH!!). Did anyone try the precompiled package? or did I miss any necessary step?

Thanks!
Best Regards,
ChenYuChih

AliZairov

  • New Member
  • *
  • Posts: 18
Hi.

app.pas
Code: Pascal  [Select][+][-]
  1. library app;
  2.  
  3. uses
  4.   Jni;
  5.  
  6. const
  7.   cName = 'Java_com_zs_Start_'; // package com.zs.Start.class
  8.        
  9. function pasString(env: PJNIEnv; this: JNIObject): JString; cdecl;
  10. begin
  11.   Result := env^.NewStringUTF(env, PChar('JNI Pascal'));
  12. end;
  13.  
  14. function JNI_OnLoad(vm: PJavaVM; reserved: Pointer): JInt; cdecl;
  15. begin
  16.   Result := JNI_VERSION_1_6;
  17. end;
  18.  
  19. function JNI_OnUnload(vm: PJavaVM; reserved: Pointer): JInt; cdecl;
  20. begin
  21.   Result := 0;
  22. end;
  23.  
  24. exports
  25.   JNI_OnLoad name 'JNI_OnLoad',
  26.   JNI_OnUnload name 'JNI_OnUnload',
  27.   pasString name cName + 'pasString';
  28.  
  29. begin
  30. end.
  31.  

Start.java
Code: Pascal  [Select][+][-]
  1. package com.zs;
  2.  
  3. import android.support.Activity;
  4. import android.os.Bundle;
  5. import android.widget.TextView;
  6.  
  7. public class Start extends Activity
  8. {
  9.     public native String pasString();
  10.  
  11.     @Override
  12.     protected void onCreate(Bundle savedInstanceState) {
  13.         super.onCreate(savedInstanceState);
  14.         setContentView(R.layout.main);
  15.  
  16.         TextView tv = (TextView) findViewById(R.id.tv);
  17.         tv.setText(pasString());
  18.     }
  19.  
  20.     static { System.loadLibrary("app"); }
  21. }
  22.  

chenyuchih

  • Jr. Member
  • **
  • Posts: 81
Yes, I did some tests as simple as your sample.
The 3.0.2 precompiler compiles without any problem but just crashed when running.
The same code compiled with Laz4Android 1.6 runs smoothly.
Did you do any special configuration?
BTW, does the NDK version matters? I use r9d.

Thank you for your response and any suggestion / idea / comment!
Chenyuchih

AliZairov

  • New Member
  • *
  • Posts: 18
Hi. 3.0.1 and 3.0.2 crash arm cpus. 3.0.0 and 3.1.1 no problem. Test arm x86.

chenyuchih

  • Jr. Member
  • **
  • Posts: 81
Hi. 3.0.1 and 3.0.2 crash arm cpus. 3.0.0 and 3.1.1 no problem. Test arm x86.

So, it's not my problem, right? Thanks for your concern and help! :)

Sincerely,
ChenYuChih

AliZairov

  • New Member
  • *
  • Posts: 18
No. This is a problem related to the FPC version. You're welcome.  :)

yuriy_sydorov

  • Full Member
  • ***
  • Posts: 158
Indeed the win32 release for android is unusable for the arm-android target.
By mistake, I had used an old NDK toolchain to compile that release.
I've rebuilt the release using a newer toolchain and uploaded it to SourceForge. FTP mirrors still contain the broken version. They will be updated later.

Please test the new release from SF:
https://sourceforge.net/projects/freepascal/files/Win32/3.0.2/fpc-3.0.2.i386-win32.cross.android.exe/download

chenyuchih

  • Jr. Member
  • **
  • Posts: 81
Indeed the win32 release for android is unusable for the arm-android target.
By mistake, I had used an old NDK toolchain to compile that release.
I've rebuilt the release using a newer toolchain and uploaded it to SourceForge. FTP mirrors still contain the broken version. They will be updated later.

Please test the new release from SF:
https://sourceforge.net/projects/freepascal/files/Win32/3.0.2/fpc-3.0.2.i386-win32.cross.android.exe/download

Thank you so much, yury.

I downloaded your new built one and do some test. Firstly I still got a bad result as previous one, compiling OK but crash when running. After modifying the config file "fpc.cfg" as follows,

Originally, in "fpc.cfg", the Android -FD paths are
"Path_to_Android_NDK\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\bin" for arm,
"Path_to_Android_NDK\toolchains\x86-4.6\prebuilt\windows\bin" for x86,
"Path_to_Android_NDK\toolchains\mipsel-linux-android-4.6\prebuilt\windows\bin" for mips.

I changed them to
"Path_to_Android_NDK\toolchains\arm-linux-androideabi-4.8\prebuilt\windows\bin" for arm,
"Path_to_Android_NDK\toolchains\x86-4.8\prebuilt\windows\bin" for x86,
"Path_to_Android_NDK\toolchains\mipsel-linux-android-4.8\prebuilt\windows\bin" for mips.

And everything became fine! At least it doesn't crash anymore in the simulator. I don't know why it works. Does the modification make sense?

Best Regards,
ChenYuChih

AliZairov

  • New Member
  • *
  • Posts: 18
Hi. The method I used.

https://i.snag.gy/Ef873x.jpg

Example armv7:

source.properties
Code: Pascal  [Select][+][-]
  1. NDK="/Volumes/DATA/Library/Android.sdk/ndk-bundle"
  2. PLF="android-14"
  3. VER="4.9"
  4.  

build.sh
Code: Pascal  [Select][+][-]
  1. sh $(dirname $BASH_SOURCE)/build_armv6.sh
  2. sh $(dirname $BASH_SOURCE)/build_armv7.sh
  3. sh $(dirname $BASH_SOURCE)/build_x86.sh
  4. sh $(dirname $BASH_SOURCE)/build_mips.sh
  5.  

build_armv7.sh
Code: Pascal  [Select][+][-]
  1. source $(dirname $BASH_SOURCE)/source.properties
  2.  
  3. PRJ="app"
  4. DIR="app"
  5.  
  6. echo "Create soruce dirs"
  7. mkdir -p $(dirname $BASH_SOURCE)/$DIR/lib/armeabi-v7a 2>&1
  8. mkdir -p $(dirname $BASH_SOURCE)/$DIR/Android/libs/armeabi-v7a 2>&1
  9.  
  10. echo "Build .so file"
  11. $(dirname $BASH_SOURCE)/bin/ppcrossarm -Tandroid -CpARMV7A -MDelphi -Fu$(dirname $BASH_SOURCE)/bin/units/arm-android -Fu$(dirname $BASH_SOURCE)/bin/units/arm-android/* -Fu$(dirname $BASH_SOURCE)/bin/units/arm-android/rtl -Fu$(dirname $BASH_SOURCE)/libs -Fl$NDK/platforms/$PLF/arch-arm/usr/lib -FD$NDK/toolchains/arm-linux-androideabi-$VER/prebuilt/darwin-x86_64/bin -FU$(dirname $BASH_SOURCE)/$DIR/lib/armeabi-v7a -o$(dirname $BASH_SOURCE)/$DIR/Android/libs/armeabi-v7a/lib$PRJ.so $(dirname $BASH_SOURCE)/$DIR/$PRJ.pas
  12.  
  13. echo "Strip output file"
  14. $NDK/toolchains/arm-linux-androideabi-$VER/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip $(dirname $BASH_SOURCE)/$DIR/Android/libs/armeabi-v7a/lib$PRJ.so
  15.  

yuriy_sydorov

  • Full Member
  • ***
  • Posts: 158
I downloaded your new built one and do some test. Firstly I still got a bad result as previous one, compiling OK but crash when running. After modifying the config file "fpc.cfg" as follows,

As I've found out, it is needed to use a toolchain version 4.7 or later for arm-android. Earlier versions produce incorrect relocations. The setup package uses the first found version of the toolchains. Therefore you need to use NDK r10 or later with the setup to get the proper toolchain as the newer NDK releases do not included incompatible toolchain versions. Or fix the config manually as you have done.

I will modify the setup to check the toolchain version for the 3.0.4 release.
« Last Edit: May 04, 2017, 12:17:31 pm by yury_sidorov »

chenyuchih

  • Jr. Member
  • **
  • Posts: 81
I downloaded your new built one and do some test. Firstly I still got a bad result as previous one, compiling OK but crash when running. After modifying the config file "fpc.cfg" as follows,

As I've found out, it is needed to use a toolchain version 4.7 or later for arm-android. Earlier versions produce incorrect relocations. The setup package uses the first found version of the toolchains. Therefore you need to use NDK r10 or later with the setup to get the proper toolchain as the newer NDK releases do not included incompatible toolchain versions. Or fix the config manually as you have done.

I will modify the setup to check the toolchain version for the 3.0.4 release.

I see. Thanks for your explanation!

Sincerely,
ChenYuChih

yuriy_sydorov

  • Full Member
  • ***
  • Posts: 158
I downloaded your new built one and do some test. Firstly I still got a bad result as previous one, compiling OK but crash when running. After modifying the config file "fpc.cfg" as follows,

As I've found out, it is needed to use a toolchain version 4.7 or later for arm-android. Earlier versions produce incorrect relocations. The setup package uses the first found version of the toolchains. Therefore you need to use NDK r10 or later with the setup to get the proper toolchain as the newer NDK releases do not included incompatible toolchain versions. Or fix the config manually as you have done.

I will modify the setup to check the toolchain version for the 3.0.4 release.

After further investigation I've found out the source of the issue. FPC 3.0.x generates "BLX label" assembler instructions, which is wrong. Only toolchains 4.7 or later change these instructions to "BL label". Earlier toolchains leave "BLX label" as is and it causes crash. In FPC trunk it is fixed and any toolchain can be used.

Just use NDK r10 or later with FPC 3.0.x to avoid issues.

chenyuchih

  • Jr. Member
  • **
  • Posts: 81
Re: Did anyone try "fpc-3.0.2.i386-win32.cross.android.exe" under windows?
« Reply #12 on: April 21, 2018, 04:27:10 am »
Sorry for digging this old post...but the same problem shows up again in "fpc-3.0.4.i386-win32.cross.android.exe"...(Lazarus 1.8.2)

Now the Android NDK version I am using is r11c, but the shared object compiled with 3.0.4 doesn't work, just crash. (The same code with 3.0.2 works fine)

The only old thing is that I am still using android API10 and 2.3.3 emulator because I have to make sure my program can run on those old devices.

Could somebody do the test and give me some hint?

Thank you very much!

ChenYuChih

chenyuchih

  • Jr. Member
  • **
  • Posts: 81
Re: Did anyone try "fpc-3.0.2.i386-win32.cross.android.exe" under windows?
« Reply #13 on: April 22, 2018, 03:13:23 am »
I tried a simplest example just as AliZairov's first reply and change the emulator to Android 4.0(API14), but the result is still no good.

(There's no problem during compiling and all the installation were follow what I did for Lazarus 1.6.4+FPC 3.0.2, so I don't think the setup is wrong)

I saw the error message in logcat is "Fatal signal 11 (SIGSEGV) at  0x00000000 (code=1)". Does it help?

Thanks for any advice or help!

ChenYuChih
« Last Edit: April 22, 2018, 05:02:34 am by chenyuchih »

bongorongo

  • Newbie
  • Posts: 6
Re: Did anyone try "fpc-3.0.2.i386-win32.cross.android.exe" under windows?
« Reply #14 on: September 13, 2018, 02:02:26 pm »
Tried this great guide, and almost got it working.
No errors until creating a new project. (LAMW [GUI] Android Module)

NDK dropdown is empty
Target API only contains 0

If I press OK I get "Invalid floating point operation." error message.

Any tips?
How to verify correct install of NDK?

 

TinyPortal © 2005-2018