Running Pascal applications in Android lazarus / 43-Android ---------------------------------------------------------------------- felipemdc · 2010-12-11 10:31 Hello, There are two ways to run Pascal apps in Android: 1> As a library connected to Java via JNI 2> As an executable run by the Java app and communicating with it via pipes Recently I succeeded in using method 2, which is running a simple FPC Pascal application in Android and showing it's WriteLn output in a message dialog: http://p-tools.svn.sourceforge.net/viewvc/p- tools/PascalNotes4Android/?pathrev=190 Basically you need to rename your app so that it looks like a .so and then upon initialization the Java app needs to copy it to a folder where it can run the application. The folder is returned by getApplicationContext().getFilesDir which points to /data/data/packagename/ and then I use chmod to make the executable runnable. I don't know how it will fare for apps running for prolonged amounts of time at the moment, some Android developers said it is possible that it won't work. The Pascal app needs to be compiled separately and placed in the lib/eabi folder. Then after that issue "ant debug" to build the APK installer. I just thought this might be useful for someone. bye, ---------------------------------------------------------------------- Riccardo Giuliani · 2010-12-11 11:00 Thank you. This is an important beginning to understand actual FPC/Lazarus potentialities on Andorid. ---------------------------------------------------------------------- felipemdc · 2010-12-16 17:25 One more milestone achieved: I managed to build a bridge which exports the Java API and the Android API to Free Pascal. Check this hello world code and screenshot: http://wiki.lazarus.freepascal.org/Android_Interface/Android_Programmi ng#Using_the_Android_API_from_Pascal The full code is here: http://p-tools.svn.sourceforge.net/viewvc/p-tools/PascalNotes4Android/ ---------------------------------------------------------------------- Leledumbo · 2010-12-16 22:49 Nice work, Felipe. Is there any detailed instruction to compile it? I mean, what SDK required, what's the target platform, etc. I wanna show this my friends (those taking mobile technology classes and programming with NetBeans ). ---------------------------------------------------------------------- herux · 2010-12-17 03:00 I'm studying this source http://rootserver.rosseaux.net/stuff/BeRoXMAndroidSrc.zip, use method 1, is not it? What is the best according to you? ---------------------------------------------------------------------- felipemdc · 2010-12-17 09:24 Quote from: herux on December 17, 2010, 04:00:44 amI'm studying this source http://rootserver.rosseaux.net/stuff/BeRoXMAndroidSrc.zip, use method 1, is not it? What is the best according to you? Yes, it uses method 1. I think it is very hard to compare them, because they are so different. In short: method 1> * Cannot access Android APIs from Pascal, if you want to use them it needs to be done in Java * Requires knowledge of Java and the JNI to program. You actually need to write part of the program in Java. * Existing Pascal applications will require extensive modifications to work in this method. Only non-GUI code can be reused * It more like Google wants you to program, so maybe more stable method 2> * Allows using the Android APIs in Pascal * You can build Android apps without any Java knowledge. The Java helper app is just a machine controlled by your Pascal code, you can just copy it to your programs and modify only the name of the main file. * Makes it feasable to port Pascal applications with minimal modifications. With this method the LCL can be ported for example and LCL programs recompiled for Android, or else you can write your GUI directly using the Android APIs in Pascal. * My current Java machine is not very optimized, so it will probably be slow for very large programs. It can be optimized in the future, however. Both allow writing non-GUI code in Pascal. Note that in both cases there are two ways to build the GUI: * Write the GUI using Android APIs -> In this case the Java-only GUI in method 1 will probably be faster, because the bindings introduce a delay, but it is probably negletible, because this isn't a bottleneck. But I don't care much, since I much prefer writing in Pascal rather then Java =) * Write the GUI using OpenGL ES -> In this case both are equivalent, although all the other points above apply ---------------------------------------------------------------------- felipemdc · 2010-12-17 12:44 Quote from: Leledumbo on December 16, 2010, 11:49:19 pm Nice work, Felipe. Is there any detailed instruction to compile it? I mean, what SDK required, what's the target platform, etc. I wanna show this my friends (those taking mobile technology classes and programming with NetBeans ). Thanks, I have put some instructions here: http://wiki.lazarus.freepascal.org/Android_Interface/Android_Programmi ng#Compiling_the_example_project_in_Linux Preparing the entire build environment can take some time, but once it is ready, building projects is very fast. ---------------------------------------------------------------------- Hansaplast · 2011-01-02 19:34 Very impressive As a Android (and Java) Noob, I found no RAD environment for Android, it would be great if Lazarus/FPC eventually could become that missing tool to develop Android Apps. I realize we are far away from materializing that dream, just wanted to express my interest ---------------------------------------------------------------------- BlueIcaro · 2011-01-10 15:57 Quote from: SteveVai on January 10, 2011, 01:51:09 pmIs the Android a Google phone? Android is a OS developed by Google, and used in some phones, tablets, etc. /BlueIcaro ---------------------------------------------------------------------- floydgonzales · 2011-01-12 07:12 This is quite interesting. I learned a bit of Pascal back in college. Maybe I'll give this a try. I can think of a few apps I'd like to do just for personal use on my phone. ---------------------------------------------------------------------- felipemdc · 2011-01-12 14:42 The link with instructions changed to here: http://wiki.lazarus.freepascal.org/Android_Interface/Native_Android_GU I ---------------------------------------------------------------------- felipemdc · 2011-01-13 11:09 Today I got button clicking and activity state (onCreate, onRestart, onPause, onStop, etc) working =D Code here: http://p-tools.svn.sourceforge.net/viewvc/p- tools/turbochessclock4android/?pathrev=209 ---------------------------------------------------------------------- laguna · 2011-01-18 07:30 after completing turbochessclock4android, what must I do to run in GalaxyS the files are located in "C:\lazarus\components\andro\turbochessclock4android\lib\i386-win32"  is correct. How are the files? androidactivity.o androidactivity.ppu androidpipescomm.o androidpipescomm.ppu androidui.o androidui.ppu javalang.o javalang.ppu turbochessclock4android.compiled turbochessclock4android.o what is the executable file? ---------------------------------------------------------------------- felipemdc · 2011-01-18 11:12 No, the executable should be in: C:\lazarus\components\andro\turbochessclock4android\android\libs\arm- eabi But Android is Linux, not Windows. The project does not specify the target Operating System, but I should have specified Linux. I will fix this in my next commit soon. You need a cross-compiler targetting arm- linux. I am actually surprised that you managed to build the project in Windows. I did specify arm architecture and I find it impossible that you have arm-win32 cross-compiler installed. ---------------------------------------------------------------------- laguna · 2011-01-18 13:54 To do this, I used: Lazarus-0.9.31-29090-fpc-2.4.3-20110118-win32.exe Lazarus-0.9.31-29090-fpc-2.4.3-20110118-cross-arm-wince-win32.exe 1) Open Project; 2) Build All; I am familiar with Linux. I know that the programs must have execute permissions. I was wondering how do I generate and execute the file, inside the Android. And how can I create a package APK. Thanks. ---------------------------------------------------------------------- felipemdc · 2011-01-18 14:39 Quote from: laguna on January 18, 2011, 02:54:26 pmTo do this, I used: Lazarus-0.9.31-29090-fpc-2.4.3-20110118-win32.exe Lazarus-0.9.31-29090-fpc-2.4.3-20110118-cross-arm-wince-win32.exe Yes, but that's a cross-compiler for Windows CE, not for Linux. I am trying to make a pre-compile installer for x86-linux -> arm- linux, but no success at the moment. You can always build your own cross-compiler. For me it wasn't that hard. I installed FPC 2.4.2, download fpctrunk from subversion and issued: make crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=/home/felipe/Programas/fpctrunk/binutils OPT=-dFPC_ARMEL INSTALL_PREFIX=/usr/ I used the instructions here: http://wiki.lazarus.freepascal.org/Setup_Cross_Compile_For_ARM QuoteI am familiar with Linux. I know that the programs must have execute permissions. I was wondering how do I generate and execute the file, inside the Android. And how can I create a package APK. Thanks. After you have built the project for arm-linux, you create the APK in the command line by doing: cd turbopascal4android/android ant debug Then the APK file will be located in turbopascal4android/android/bin You need to have ant installed for this to work, and also to have the android SDK installed. You need to change the Android SDK location in turbopascal4android/android/local.properties ---------------------------------------------------------------------- avra · 2011-01-19 08:25 CodeTyphon is very easy setup of FPC/Lazarus cross compiler with 4 hosts and 16 targets (including arm linux). •    4 CPU-Operating Systems Host Layers icon5 (Win32, Win64, Linux32, Linux64). •    16 CPU-Operating Systems Target Layers. icon5 •    Win64 Layer has Dual Personality (Win64 and Win32). •    Win32 Layer is Cross-Build Center with Cross Elements for:       arm-Wince       arm-Linux       arm-Embedded  (freepascal only)       arm-gba            (freepascal only)       arm-nds            (freepascal only)       i386-Win32       i386-Linux       i386-FreeBSD       i386-Haiku         (freepascal only)       x86_64-Win64       x86_64-Linux       x86_64-FreeBSD       powerpc-Linux       powerpc64-Linux  (freepascal only)       sparc-Linux       sparc-Solaris      (freepascal only) http://www.pilotlogic.com/sitejoom/index.php?option=com_content&view=a rticle&id=96&catid=68&Itemid=147 ---------------------------------------------------------------------- marcov · 2011-01-19 10:37 Quote from: avra on January 19, 2011, 09:25:11 amCodeTyphon is very easy setup of FPC/Lazarus cross compiler with 4 hosts and 16 targets (including arm linux). Avra, I don't mind you doing a bit of CodeTyphon advertising when it is on-topic, but at least try to provide some realworld information relating to the topic instead of simply copying the birds-eye view from their website. You can think of : - own experiences using codetyphon for various arm-linux targets. (does it really work?) - binutils versions - devices supported - eabi versions supported - floating point yes/no ? etc All I can seem to find is a general set of arm-linux binutils which sounds it is probably EABI 0, which is next to useless for modern devices. ---------------------------------------------------------------------- felipemdc · 2011-01-27 15:12 Quote from: felipemdc on January 18, 2011, 03:39:24 pmI am trying to make a pre-compile installer for x86-linux -> arm-linux, but no success at the moment. You can always build your own cross-compiler. For me it wasn't that hard. I installed FPC 2.4.2, download fpctrunk from subversion and issued: make crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=/home/felipe/Programas/fpctrunk/binutils OPT=-dFPC_ARMEL INSTALL_PREFIX=/usr/ I used the instructions here: http://wiki.lazarus.freepascal.org/Setup_Cross_Compile_For_ARM Ok, I managed to build a cross-compiler, but haven't yet tested it much. I have placed my cross-compiler here: https://sourceforge.net/projects/p- tools/files/Free%20Pascal%20for%20ARM/ Here is an rpm with cross-arm-binutils: http://rpm.pbone.net/index.php3/stat/4/idpl/14252825/dir/mandriva_2010 /com/cross-arm-binutils-2.20.51.0.4-2mnb2.i586.rpm.html ---------------------------------------------------------------------- felipemdc · 2011-02-06 14:44 Ok, I managed to get instruction about how to install the FPC which I compiled: http://wiki.lazarus.freepascal.org/Android_Interface#Using_the_pre- compiled_compiler These instructions should set up a x86-linux -> arm-linux cross- compiled which is appropriate for use for Android. ---------------------------------------------------------------------- brelstad · 2011-03-09 22:32 Hi, Felipe, two friends and myself are in the process of converting from Delphi to Lazarus. (Instead of Java/Android, we discovered your work with the Android interface.) How will you handle bitmaps? Will the bitmap be created in the Java GUI and then made accessible in Lazarus through pipes? Or will it be possible to manipulate a TBitmap in Pascal and then copy it through pipes to a "bitmap-view" in the Java GUI? Thanks, Bengt ---------------------------------------------------------------------- felipemdc · 2011-03-10 10:08 I haven't yet come to that, but I think that the best solution is using a surface which is accessible from native code. There are some possibilities: 1> The Surface API for Android 2.3+ (maybe accessible with some tricks in previous versions?) 2> An OpenGL ES surface 3> Just put it through the pipes as you mentioned I am more inclined towards option 2. Contributions are of course very welcome. ---------------------------------------------------------------------- nighthawk09 · 2011-04-06 10:20 I've developed an application in fpc-mac. And now would like to port that to android. I've started checking the sample of the turbochessclock4android, on my windows machine. Done the following: A. Downloaded the eclipse + ADT (android plug in for that).. B. Installed the android emulation and sdk C. downloaded the fpc-android sample file D. Opened a new android project under the eclipse, and added all the java classes for that. E. Tried running the android fpc example on the emulator. It raises an error that it can not run the application. (Probably due to the fact that I haven't even added the pascal compiled code for that)., * What do I need to do in order to compile the pascal code? * How is the compiled pascal objects connected to the java classes compiled files? * What do I need to do in order to combine the compiled java classes and the pascal objects? * To create the APK I just ran the application from eclipse using the run as "Android app" (using the ADT Plugin). Is there a way to set the eclipse environment and make the pascal code compiled there as part of a whole project for android? ---------------------------------------------------------------------- felipemdc · 2011-04-06 11:24 I've answered some stuff in the mailling list on the thread [fpc- pascal] Compiling android example ---------------------------------------------------------------------- felipemdc · 2011-04-06 11:27 Quote from: nighthawk09 on April 06, 2011, 12:20:11 pm* What do I need to do in order to combine the compiled java classes and the pascal objects? Nothing. In Lazarus opening Project->Build is enough. Free Pascal puts the executable into android/libs/armeabi Then when you run ANT, it will put the Pascal program inside the APK package. Quote* To create the APK I just ran the application from eclipse using the run as "Android app" (using the ADT Plugin). Is there a way to set the eclipse environment and make the pascal code compiled there as part of a whole project for android? If it works like ANT then you don't need to do anything. Just build the Pascal code before building the APK ---------------------------------------------------------------------- bigdude · 2011-04-19 16:54 Sorry for this NOOB ANT question.. I need help with a path/build issue. I have been trying to build the chessclock sample and ran into problems with ANT. The Lazarus part went fine and the library is built, but when I try to do a debug build with ANT it fails (the mixed forward and backward slashes below are probably the problem, but how can they be fixed) C:\android-chessclock\android>ant debug Buildfile: C:\android-chessclock\android\build.xml     [setup] Android SDK Tools Revision 10     [setup] Project Target: Android 2.1-update1 --- OMITTED SUCCESSFUL STEPS -resource-src:      [echo] Generating R.java / Manifest.java from the resources...  [aapt.exe] invalid resource directory name: C:\android- chessclock\android\res/drawable-hpdi  [aapt.exe] invalid resource directory name: C:\android- chessclock\android\res/drawable-lpdi BUILD FAILED C:\Archivos de programa\Android\android- sdk\tools\ant\main_rules.xml:310: null returned: 1 Total time: 1 second ---------------------------------------------------------------------- felipemdc · 2011-04-20 08:38 Go to C:\android-chessclock\android\ and open all files in this directory in a text editor, for example Notepad++ and search for the place of the wrong slash. It's not really much, one can quickly read all files. ---------------------------------------------------------------------- bigdude · 2011-04-20 19:02 I checked all of the files in that folder again and none of them have slashes faced that way. In fact the path to the android project base is not even present in any of those files. I beleive the problem is the basedir that is being provided to the android scripts by ANT, but I do not know how to override that. It looks like the code base directory is being provided with backslashes and then the scripts are appending with forward slashes. It would probably work with either one, but it chokes on the mix.. Could it be that the ant rules in the version of the android SDK I am using (2.1 lvl 7) have issues on the windows platform ?? ---------------------------------------------------------------------- felipemdc · 2011-04-20 20:02 Quote from: bigdude on April 20, 2011, 09:02:59 pmCould it be that the ant rules in the version of the android SDK I am using (2.1 lvl 7) have issues on the windows platform ?? I have no idea ... everyone in my work uses Linux for Android development. But this is a very generic problem, you could try asking in other places too. I tried googling for it, but I couldn't find anything. ---------------------------------------------------------------------- bgrimes · 2011-05-21 06:03 I was wandering through the android market the other day and found that there is already a pascal interpreter for the android platform!  I was really happy to see that it is already available. I noticed though that it was already out for about a year already. There are some comments though that do not favor pascal as they are saying that it needs a little more work to be on the right level.