Lazarus on Windows for Android lazarus / 43-Android ---------------------------------------------------------------------- polypress · 2013-08-12 08:33 I am looking to get a new smart phone. The old one is based on Windows Mobile 6.5 and has worked well but is slow. Applications can crash if more than a few are loaded. The new phone would be Windows Phone 8 or Android based, and applications written for WM6.5 (WinCE) are not compatible with either of these. Can Android applications be written on Windows XP based Lazarus/FPC (1.0.10/2.6.2) or does is have to be Linux based Lazarus/FPC? Regards ---------------------------------------------------------------------- Leledumbo · 2013-08-12 16:32 QuoteCan Android applications be written on Windows XP based Lazarus/FPC (1.0.10/2.6.2)Yes, but not with FPC 2.6.2. Use FPC trunk with native arm-android support (the hacked 2.5.1 might work, but I don't suggest that anymore) Quoteor does is have to be Linux based Lazarus/FPC?No ---------------------------------------------------------------------- jmpessoa · 2013-08-12 17:59 Hi, From this thread: Lazarus1.1 For Android -FPC2.7.1- http://forum.lazarus.freepascal.org/index.php/topic,20918.msg121775.ht ml#msg121775 You can download here: https://skydrive.live.com/?cid=89ae6b50650182c6&id=89AE6B50650182C6%21 149 See the zariq post here: http://forum.lazarus.freepascal.org/index.php/topic,21544.0.html Greetings! ---------------------------------------------------------------------- polypress · 2013-08-16 11:22 I have tried to access the skydrive site but each time it causes ie8 to crash. Is this site or this link OK? Please confirm before I try again. Regards ---------------------------------------------------------------------- jmpessoa · 2013-08-18 00:10 Sorry. Please, try this: https://skydrive.live.com/?cid=89AE6B50650182C6&id=89AE6B50650182C6%21 129 or: https://skydrive.live.com/?cid=89ae6b50650182c6 And this:       "Laz4Android1.1-41139-FPC2.7.1.7z" Thank you. ---------------------------------------------------------------------- polypress · 2013-08-19 13:04 Thank you for the links jmpessoa. I have downloaded the files and installed them, creating a running version of 1.1/2.7.1 together with various files such as arm-linux- androideabi-as.exe, arm-linux-androideabi-id.exe, arm-linux- androideabi-strip.exe, but I'm not sure what to do with them now. If I try to use them in the environment file path then I'm told it should be ppcrossarm.exe (as for wince, but fpc.cfg is missing) or fpc.exe or ppc386.exe (as for win32). I have project compiler target os as android and cpu family as arm. Is there a link to show how to use this installation for android? Regards ---------------------------------------------------------------------- polypress · 2013-08-19 14:54 Further to my last post, I have gone through the pdf file which came with the installation. Unfortunately it is in Chinese (with a little English content) showing a test with a project called androidlcltest.lpr. On testing it with the paths setup as best I could with the information available, it has come up with errors such as "illegal parameter -CpARMV6" and "Fatal: cannot find unit system used by fcllaz of package FCL" which it appears to be trying to register, and this prevents further processing. Any help to resolve this one example would be appreciated. If I can get this one to work, then hopefully I can get other more demanding applications to work. ---------------------------------------------------------------------- Leledumbo · 2013-08-19 16:09 QuoteI have downloaded the files and installed them, creating a running version of 1.1/2.7.1 together with various files such as arm- linux-androideabi-as.exe, arm-linux-androideabi-id.exe, arm-linux- androideabi-strip.exe, but I'm not sure what to do with them now.ld and as are linker and assembler, respectively. strip is not really required, you can just tell the compiler not to generate debugging info. You'll need to rename the linker and assembler prefix to arm- linux- (I assume this FPC version still uses the hacked arm-linux target instead of native arm-android), because by default fpc.cfg only contains -XP$FPCTARGET- which will be expanded to (on arm-linux target) -XParm-linux-, which will make searching of assembler and linker fails, because the name differs (e.g. arm-linux-androideabi-as instead of arm-linux-as). You can also modify the -XP in fpc.cfg or specificially specify -XP only for this project to match the name of the assembler and linker. QuoteIf I try to use them in the environment file path then I'm told it should be ppcrossarm.exe (as for wince, but fpc.cfg is missing) or fpc.exe or ppc386.exe (as for win32)fpc -Parm will call ppcrossarm while fpc only will call the host compiler (ppc386 in your case). QuoteI have project compiler target os as android and cpu family as arm.If you're using hacked arm-linux, then your os target should be linux instead of android. QuoteOn testing it with the paths setup as best I could with the information available, it has come up with errors such as "illegal parameter -CpARMV6"The compiler might not be built with ARMv6 code generation support, you should know exactly how the compiler is built (i.e. what options are passed). Quoteand "Fatal: cannot find unit system used by fcllaz of package FCL"Either fpc.cfg misses path to arm-linux version of the basic units or because of the previous error. ---------------------------------------------------------------------- polypress · 2013-08-19 17:44 Thank you for your prompt response Leledumbo. It will take a while to absorb and incorporate all of your suggestions so I probably won't be live for a while. However, the android files are of the form "arm-linux-androideabi- as.exe". Are you saying I need to convert its name (to arm- androideabi-as.exe or arm-android-as.exe or arm-linux-as.exe) or to change the file name called from lazarus to "arm-linux-androideabi- as.exe" or to change file names within fpc.cfg? What are -XP$FPCTARGET- (the XP bit) and -XParm-linux- and fpc -Parm and where are they called? I don't know if I'm using a hacked arm-linux - it came from Skydrive which seems to be connected with Microsoft, so I assume it shouldn't be hacked. How can I find out if the compiler was built with ARMv6 code generation support? Which part of fpc.cfg defines the path to the arm-linux version of the basic units? The download was supposedly a fully working 1.1/2.7.1 + example, so could it be the environment needs to be modified? I am familiar with assembler and Delphi (Lazarus) programming, but this all seems a little more difficult. Regards ---------------------------------------------------------------------- jmpessoa · 2013-08-19 23:58 Hi! 1. From original Post:     http://forum.lazarus.freepascal.org/index.php/topic,20918.msg12177 5.html#msg121775 After decompression: --> Find "build.bat" batch file, right-click for edit. if necessary modify line 4:      SETFPC_BIN_PATH = F:\laz4android         for something more convenient for you.      For me:  SETFPC_BIN_PATH = C:\laz4android  --> now double-click the "build.bat' to build Lazarus and wait for the completion of the batch... 2.  To compile "androidlcltest" See the zariq post here:      http://forum.lazarus.freepascal.org/index.php/topic,21544.0.html 3. After some experimentation I got the following configuration (for my comfort or laziness  )     as shown in the accompanying figures (Attachments).    My Comment about "Other"    I think just  this is necessary:    -dANDROID -Xd -CpArmV6 -CfSoft -FLC:\adt32\ndk7\platforms\android-8\arch-arm\usr\lib\libdl.so     where -CSoft can may be substituted by -CVfpV3 ... etc.         In fact, if you can omit this part    -FUC:\adt32\eclipse\workspace\App1\obj\JNIHello -oC:\adt32\eclipse\workspace\App\libs\armeabi\libjnihello.so and act manually this tasks.... Greetings! ---------------------------------------------------------------------- Leledumbo · 2013-08-20 16:15 I'll wait until you do what jmpessoa say before I answer, perhaps the package is already designed as such (i.e. requires running some batch file before used). ---------------------------------------------------------------------- truetom · 2013-08-21 05:31 HI! I am the founder of this package,as jmpessoa say this package can compiled androidlcltest project,you just do this: 1.download laz4android1.1-41139-FPC2.7.1.7z from http://sdrv.ms/12cHbIZ 2.decompression this file to any path,etc : c:\laz4android 3.edit "build.bat" line 4   SET FPC_BIN_PATH = F:\laz4android  this line change to  SET FPC_BIN_PATH = c:\laz4android 4.now double click the "build.bat",now you can see a command form is running ,it's building lazarus.exe,please waiting for build finished. 5.after builded lazarus.exe ,you can run the lazarus.exe to open the androidlcltest.lpr ,which is location c:\laz4android\examples\androidlcl. before compile this project ,you must download android NDK and extract it. 7.adjust project's libraries to your NDK path,this menu: project->project options->paths(left)->libraries(right) . 8.if the libraries path is correct ,now can CTRL+F9 to compile this androidlcltest project, a file which name is "liblclapp.so" should created at C:\laz4android\examples\androidlcl\android\libs\armeabi 9.now edit "generate_debug_key.bat" ,run it to create a key.you must already installed JDK ok. 10. edit "build_debug_apk.bat",run it to build a android apk package.you must already installed Android SDK ok. hope can helped you! Greeting! sorry for my bad english. ---------------------------------------------------------------------- polypress · 2013-08-23 12:48 Hello truetom I have followed your instructions fully (I think) but when I get to compile with Ctrl+F9 I am given the following message "Fatal: cannot find unit system used by fcllaz of package FCL". According to Leledumbo this is because either fpc.cfg misses path to arm-linux version of the basic units or because the compiler might not be built with ARMv6 code generation support, [you should know exactly how the compiler is built (i.e. what options are passed)]. I have searched fpc.cfg and there is no sign of the path for arm-linux, but also, is the compiler built with ARMv6 code generation support? If your installation works OK, then I assume it is, or could each installation have different levels of (ARMv6) support? Would it help if I attached some files to these posts? If so, which do you suggest? Regards ---------------------------------------------------------------------- jmpessoa · 2013-08-23 16:54 Hi! Do you did the zariq hint?  http://forum.lazarus.freepascal.org/index.php/topic,21544.0.html QuoteTo compile androidlcltest had to change the target from Linux to android and deselect -WR(relocatable) option under code generation. didn't have to change paths to android ndk / sdk which I have installed in c:\android. Also the "so" extention is not added, so need to rename the file or add it in the project options. Greetings! ---------------------------------------------------------------------- truetom · 2013-08-25 07:26 Hello polypress. I guess you select the project's Target OS is wrong. Check this menu: Project -> project options -> Code generation (left) -> Target OS:android    Target CPU family: arm  (right) ---------------------------------------------------------------------- polypress · 2013-08-25 10:44 I replied a while ago but it doesn't seem to have registered on the forum. I have overcome the fcllaz/FCL problem by changing the environment. Now I get a problem with "Unknown mandatory EABI object attribute 44" on linking the project. mbdev received a similar message and overcame it by using NDK7C instead of NDK8C. I am using ndk-r9. Does it mean I need to change it to a different ndk? If so, why? Will I need to change ndk for different projects, or is it a question of stability? I kave updated the sdk which included an "ARM EABI v7a System Image" installation, but that doesn't seem to make a difference. Which version of NDK and SDK did you use to successfully compile the project? Regards ---------------------------------------------------------------------- truetom · 2013-08-25 14:07 Hello polypress.I use Android NDK r7. ---------------------------------------------------------------------- polypress · 2013-08-25 15:55 Hello truetom Yes. I've converted to ndk 7 (very limited availability - almost everything refers to ndk 9) and I've generated liblclapp.so but I can't convert it to .apk. I've edited generate_debug_key.bat and build_debug_apk.bat and run both but on searching the directories, there's no sign of liblclapp.apk. The DOS windows flash through so rapidly that you can't see what's happening and if there are any errors. Any clues? Regards ---------------------------------------------------------------------- polypress · 2013-08-25 16:22 I've slowed down the build_debug_apk.bat by piping it to a text file and examining the results:- Could not find c:\laz4android\examples\androidlcl\android\bin\androidlcltest.ap_ Could not find c:\laz4android\examples\androidlcl\android\bin\androidlcltest.apk aapt is not recognized as an internal or external command Could not find c:\laz4android\examples\androidlcl\android\bin\androidlcltest- unsigned.apk apkbuilder is not recognized as an internal or external command unable to open bin\androidlcltest-unsigned.apk as zip archive. As far as I can tell all paths are OK so what's wrong? Regards ---------------------------------------------------------------------- truetom · 2013-08-26 01:36 Hello polypress. This is my build_debug_apk.bat file: Code: [Select]REM Adjust these paths to yours SET PATH=C:\Progra~1\Android\android- sdk\tools;C:\Progra~1\Android\android-sdk\platform- tools\;C:\Progra~1\Java\jdk1.6.0_30\bin SET APP_NAME=androidlcltest SET ANDROID_HOME=C:\Progra~1\Android\android-sdk SET APK_SDK_PLATFORM=C:\Progra~1\Android\android- sdk\platforms\android-8 SET APK_PROJECT_PATH=F:\laz4android\examples\androidlcl\android REM Create necessary directory Structure mkdir bin mkdir bin\classes mkdir gen mkdir gen\com mkdir gen\com\pascal mkdir gen\com\pascal\lcltest mkdir raw mkdir raw\lib mkdir raw\lib\armeabi REM Cleanup del bin\%APP_NAME%.ap_ del bin\%APP_NAME%.apk del raw\lib\armeabi\*.so REM More directory preparation copy libs\armeabi\*.so raw\lib\armeabi\ REM Resource compilation call aapt p -v -f -M AndroidManifest.xml -F bin\%APP_NAME%.ap_ -I %APK_SDK_PLATFORM%\android.jar -S res -m -J gen raw REM Java compiler call javac -verbose -encoding UTF8 -classpath %APK_SDK_PLATFORM%\android.jar -d bin\classes src\com\pascal\lcltest\LCLActivity.java REM Convert the java bytecode to dalvik bytecode call java -Djava.ext.dirs=%ANDROID_HOME%\platform-tools\lib\ -jar %ANDROID_HOME%\platform-tools\lib\dx.jar --dex --verbose --output=%APK_PROJECT_PATH%\bin\classes.dex %APK_PROJECT_PATH%\bin\classes REM It seams that dx calls echo off @echo on REM Now build the unsigned APK del %APK_PROJECT_PATH%\bin\%APP_NAME%-unsigned.apk call java -classpath %ANDROID_HOME%\tools\lib\sdklib.jar com.android.sdklib.build.ApkBuilderMain %APK_PROJECT_PATH%\bin\%APP_NAME%-unsigned.apk -v -u -z %APK_PROJECT_PATH%\bin\%APP_NAME%.ap_ -f %APK_PROJECT_PATH%\bin\classes.dex REM Generating on the fly a debug key rem keytool -genkey -v -keystore bin\LCLDebugKey.keystore -alias LCLDebugKey -keyalg RSA -validity 10000 -dname NAME -storepass senhas -keypass senhas REM Signing the APK with a debug key del bin\%APP_NAME%-unaligned.apk jarsigner -verbose -keystore bin\LCLDebugKey.keystore -keypass 123456 -storepass 123456 -signedjar bin\%APP_NAME%-unaligned.apk bin\%APP_NAME%-unsigned.apk LCLDebugKey REM Align the final APK package zipalign -v 4 bin\%APP_NAME%-unaligned.apk bin\%APP_NAME%.apk REM call and pause together allow us to see the results in the end pause In this batch file, as you saw , my batch file is not called apkbuilder.bat and dx.bat. So it can used to any version of Andrid SDK . ---------------------------------------------------------------------- zariq · 2013-08-26 02:11 It's complaining about a missing apkbuilder. There was a discussion some months ago about newer sdk's not having apkbuilder. Could be your paths are are wrong, or are referring to old paths if you haven't removed it. It can't find aapt  either, which is in android- sdk\platform-tools, so probably wrong paths. Regarding the window closing, put a pause at the end of the batch file. ---------------------------------------------------------------------- polypress · 2013-08-26 09:47 I seem to have lost my latest post again, so here it is, again:- Hello truetom I can't find any reference to apkbuilder.bat or dx.bat in your code or mine, unless that is in the "call apkbuilder' script. A major difference is :- Mine:- call apkbuilder %APK_PROJECT_PATH%\bin\%APP_NAME%-unsigned.apk -v -u -z %APK_PROJECT_PATH%\bin\%APP_NAME%.ap_ -f %APK_PROJECT_PATH%\bin\classes.dex Yours:- call java -classpath %ANDROID_HOME%\tools\lib\sdklib.jar com.android.sdklib.build.ApkBuilderMain %APK_PROJECT_PATH%\bin\%APP_NAME%-unsigned.apk -v -u -z %APK_PROJECT_PATH%\bin\%APP_NAME%.ap_ -f %APK_PROJECT_PATH%\bin\classes.dex Perhaps this is what you mean. Another difference is:- Mine:- SET APK_SDK_PLATFORM=C:\Android\sdk\platforms\android-18 jdk1.6.0_45 Yours:- SET APK_SDK_PLATFORM=C:\Android\sdk\platforms\android-8 jdk1.6.0_30 When downloading the sdk it only had -18, not -8, although it uses -8 in ndk platforms. They don't have the same folders in them so I assume this doesn't cause any errors. ndk r7 only goes up to android-14, so I standardized on -8 throughout (except sdk platform of course - that only had android-18). I use the latest jdk (perhaps this is a mistake!?). Using your code I can now get androidlcltest-unsigned.apk but not androidlcltest.apk (but I don't really understand why). Is this right, or am I still missing something? On examining the command prompt window in more detail, it says it can't find androidlcltest-unaligned.apk (and aapt is not internal or external command, still). Hello zariq Changing the line of code above has overcome one problem, but I can't find any file aapt.* in the sdk platform-tools folder or anywhere within the sdk (I've renamed the folder from android-sdk to sdk for a shorter path - I hope this doesn't upset anything). It also says:- Could not find [path]androidlcltest.ap_ and [path]androidlcltest.apk but I thought it is the purpose of this batch file to build such a file. This is very strange, Regards to both ---------------------------------------------------------------------- polypress · 2013-08-26 10:36 Good News. I've found aapt.exe in buid-tools of the sdk. Including this in the path of build_debug_apk.bat gets me further. Now it generates androidlcltest.ap_ but not androidlcltest.apk Thank you both. I'm nearer, but not there yet! ---------------------------------------------------------------------- truetom · 2013-08-26 12:22 Hello polypress. QuotePerhaps this is what you mean. Yes , it's my mean. Quotejdk1.6.0_45 Yours:- SET APK_SDK_PLATFORM=C:\Android\sdk\platforms\android-8 jdk1.6.0_30 JDK is not question. QuoteUsing your code I can now get androidlcltest-unsigned.apk but not androidlcltest.apk (but I don't really understand why). Is this right, or am I still missing something? androidlcltest-unsigned.apk is a not sign apk file.you can sign it by yourself.this command: jarsigner -verbose -keystore bin\LCLDebugKey.keystore -keypass [password,etc 123456]  -storepass [password,etc 123456] -signedjar bin\%APP_NAME%-unaligned.apk bin\%APP_NAME%-unsigned.apk LCLDebugKey androidlcltest-unaligned.apk is a not align apk file,this command: zipalign -v 4 bin\%APP_NAME%-unaligned.apk bin\%APP_NAME%.apk Of course after sign the apk,you also don't must align the apk, it's already can install to android device. ---------------------------------------------------------------------- zariq · 2013-08-26 14:35 Before building use generate_debug_key.bat. where it asks for password enter senhas unless you have changed it in build_debug_apk.bat. If it says wrong key or something then delete the bin folder, generate the key and then build. If you were to post the contents of the two bat files and your paths, maybe somebody might spot something. ---------------------------------------------------------------------- polypress · 2013-08-26 14:39 Eureka! It works. Androidlcltest.apk copied to android phone and is working well, including the GPS position part. Now I have to see how to convert old wm6.5 apps for this. Thank you all. Regards ---------------------------------------------------------------------- polypress · 2013-08-28 14:18 Hello All Back again. androidlcltest works well on the android phone, so I've been converting other wm6.5 applications for use on the same phone. Icompiles and transfers to the phone OK, but it will not run :- "Unfortunately, [app] has stopped.". I assumed this was due to the [app]Activity.java file being incorrect, so I've gone all through it with JBuilder but I can't see the reason. Do you have a blank java activity file that I can work on. For the first app all I need to display are 6 edit boxes, 2 buttons and some floating point calculations. I don't know if there is too much resource in my java file for the requirements of the app. Regards ---------------------------------------------------------------------- Leledumbo · 2013-08-28 14:42 QuoteIcompiles and transfers to the phone OK, but it will not run :- "Unfortunately, [app] has stopped."adb logcat output please... ---------------------------------------------------------------------- polypress · 2013-08-28 15:27 Hi I've tried adb logcat output [app].apk from the sdk platform-tools folder but it's just waiting for device and waiting and waiting... Perhaps I haven't got everything installed. Do I need an extra package? Regards ---------------------------------------------------------------------- Leledumbo · 2013-08-29 15:57 QuoteI've tried adb logcat output [app].apk from the sdk platform- tools folder but it's just waiting for device and waiting and waiting... Perhaps I haven't got everything installed. Do I need an extra package?I don't think so, but have you enabled USB debugging on the device? ---------------------------------------------------------------------- polypress · 2013-08-29 21:03 I was examining the apk file on the computer. Should I have done in on the phone (with device debugging turned on)? Regards ---------------------------------------------------------------------- polypress · 2013-08-30 09:29 I may have found part of the problem with adb logcat. I assumed it was analyzing the [app].apk file, but on further reading it is the phone device which produces the log, so it needs to access that device. I have the development computer isolated from all connections in order to protect it, and everything (ndk, sdk, jdk etc) is set up on this, with the [app].apk file transferred via sdcard. I'll either have to set everything up again on the connected computer, or find another way to identify why I get the "Unfortunately, [app] has stopped." message. ---------------------------------------------------------------------- polypress · 2013-08-30 14:48 When running build_debug_apk.bat it says there are no class files specified, and none are written to \bin\classes\com\pascal\[app]\. I see they should be of the form [app]Activity.class with various inserted names (such as [app]Surface etc) which are defined in the [app]Activity.java file. Are these written by / from the Activity.java file? If so what code is it likely to be missing? Regards ---------------------------------------------------------------------- Leledumbo · 2013-08-30 15:08 QuoteI assumed it was analyzing the [app].apk file, but on further reading it is the phone device which produces the log, so it needs to access that deviceLooks like you've just found out how adb logcat works QuoteWhen running build_debug_apk.bat it says there are no class files specified, and none are written to \bin\classes\com\pascal\[app]\. I see they should be of the form [app]Activity.class with various inserted names (such as [app]Surface etc) which are defined in the [app]Activity.java file. Are these written by / from the Activity.java file? If so what code is it likely to be missing?No idea since I don't use the .bat file (not on Linux), I use `ant` which should work on any platforms and I have those .class in the path you specify. ---------------------------------------------------------------------- polypress · 2013-08-30 15:31 I prefer not to have to return to Linux. It was giving problems before and squandering resources. Assuming the .class files come from the activity java file, even in Linux, do you have a basic activity.java file that I could inspect? I have tried using LCLActivity.java as a starter for the new app, but that doesn't work. I assume all references to "lcl" in that file refer to variables and functions associated with the app. I have changed each reference to one associated with the new app, including respecting any case sensitivities. Are there any "lcl" containing variables or functions which are android keywords and whose name should be maintained? Regards ---------------------------------------------------------------------- zariq · 2013-08-30 16:00 why don't you use delphifreaks program to set up your projects structure? ---------------------------------------------------------------------- polypress · 2013-08-30 16:23 Do you have a link? I can't find one on Google ---------------------------------------------------------------------- zariq · 2013-08-30 16:50 Look in this forum, android section. In the What's wrong with my apk file thread, reply seven.  I had to edit the batch files to get the resulting project to compile, therefore I would suggest you download the first version, it's called apkmanager and the template project from December last year. Best thing to would be to study the code and change it for your needs. Doing so will help you better understand the project files. ---------------------------------------------------------------------- Leledumbo · 2013-08-31 12:32 QuoteAssuming the .class files come from the activity java file, even in Linux, do you have a basic activity.java file that I could inspect? I have tried using LCLActivity.java as a starter for the new app, but that doesn't workThe only activity class required is that LCLActivity.java, you might need to only change the package name (and the respective directory hierarchy) and the .so name (look for System.loadLibrary in the static block at the end of the class). Again, an adb logcat output would be good to find where the problem is. Install the apk from adb will also reveal installation error message. QuoteI assume all references to "lcl" in that file refer to variables and functions associated with the app. I have changed each reference to one associated with the new app, including respecting any case sensitivities.This should not be required unless you want to support more features. QuoteAre there any "lcl" containing variables or functions which are android keywords and whose name should be maintained?Nope. ---------------------------------------------------------------------- polypress · 2013-09-01 15:13 This one is a problem with TStringGrid. Although it's more to do with LCL, it is a problem specific to Android, as wince and win32 are OK. I am using (a component based on) TStringGrid but the scrollbars do not show. I need to load 37000 rows into it and therefore need (vertical) scrollbars. I haven't seen a post referring to this (apart from a possible reference to a bug list). Has anyone else come across this as a problem? Regards