Did anyone try "fpc-3.0.2.i386-win32.cross.android.exe" under windows? lazarus / 43-Android ---------------------------------------------------------------------- chenyuchih · 2017-04-17 06:28 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 · 2017-04-29 20:47 Hi. app.pas Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i library app; uses  Jni;  const  cName = 'Java_com_zs_Start_'; // package com.zs.Start.class        function pasString(env: PJNIEnv; this: JNIObject): JString; cdecl; begin  Result := env^.NewStringUTF(env, PChar('JNI Pascal'));end;  function JNI_OnLoad(vm: PJavaVM; reserved: Pointer): JInt; cdecl;begin  Result := JNI_VERSION_1_6;end; function JNI_OnUnload(vm: PJavaVM; reserved: Pointer): JInt; cdecl;begin  Result := 0;end; exports  JNI_OnLoad name 'JNI_OnLoad',  JNI_OnUnload name 'JNI_OnUnload',  pasString name cName + 'pasString'; beginend.  Start.java Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i package com.zs; import android.support.Activity;import android.os.Bundle;import android.widget.TextView; public class Start extends Activity{    public native String pasString();     @Override  protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);         TextView tv = (TextView) findViewById(R.id.tv);        tv.setText(pasString());    }     static { System.loadLibrary("app"); }} ---------------------------------------------------------------------- chenyuchih · 2017-04-30 00:20 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 · 2017-04-30 11:42 Hi. 3.0.1 and 3.0.2 crash arm cpus. 3.0.0 and 3.1.1 no problem. Test arm x86. ---------------------------------------------------------------------- chenyuchih · 2017-04-30 12:33 Quote from: AliZairov on April 30, 2017, 01:42:32 pmHi. 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 · 2017-04-30 14:31 No. This is a problem related to the FPC version. You're welcome. ---------------------------------------------------------------------- yuriy_sydorov · 2017-05-03 15:12 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 · 2017-05-04 07:18 Quote from: yury_sidorov on May 03, 2017, 05:12:13 pmIndeed 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 · 2017-05-04 08:17 Hi. The method I used. https://i.snag.gy/Ef873x.jpg Example armv7: source.properties Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i NDK="/Volumes/DATA/Library/Android.sdk/ndk- bundle"PLF="android-14"VER="4.9"  build.sh Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sh $(dirname $BASH_SOURCE)/build_armv6.shsh $(dirname $BASH_SOURCE)/build_armv7.shsh $(dirname $BASH_SOURCE)/build_x86.shsh $(dirname $BASH_SOURCE)/build_mips.sh  build_armv7.sh Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i source $(dirname $BASH_SOURCE)/source.properties PRJ="app"DIR="app" echo "Create soruce dirs"mkdir -p $(dirname $BASH_SOURCE)/$DIR/lib/armeabi-v7a 2>&1mkdir -p $(dirname $BASH_SOURCE)/$DIR/Android/libs/armeabi-v7a 2>&1 echo "Build .so file"$(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 echo "Strip output file"$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 ---------------------------------------------------------------------- yuriy_sydorov · 2017-05-04 10:15 Quote from: chenyuchih on May 04, 2017, 09:18:03 amI 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. ---------------------------------------------------------------------- chenyuchih · 2017-05-04 13:02 Quote from: yury_sidorov on May 04, 2017, 12:15:32 pmQuote from: chenyuchih on May 04, 2017, 09:18:03 amI 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 · 2017-05-04 16:11 Quote from: yury_sidorov on May 04, 2017, 12:15:32 pmQuote from: chenyuchih on May 04, 2017, 09:18:03 amI 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 · 2018-04-21 02:27 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 · 2018-04-22 01:13 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 ---------------------------------------------------------------------- bongorongo · 2018-09-13 12:02 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? ---------------------------------------------------------------------- Handoko · 2018-09-13 12:52 Try to download and use the lower version of the NDK. I tested on Linux, I remember the NDK dropdown was empty when I download and used the latest version of the Android NDK. And I have missing ant's build.xml when I used the latest version of SDK. Now I use Android NDK r11c and SDK Tools r25.2.5. It works. ---------------------------------------------------------------------- jmpessoa · 2018-09-13 22:18 QuoteNDK dropdown is empty Target API only contains 0 You can look for "....sdk/platform" folder. Empty? and You can look for "....ndk/platform" folder. Empty?