Recent

Author Topic: Running Pascal applications in Android  (Read 62941 times)

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Running Pascal applications in Android
« on: December 11, 2010, 11:31:02 am »
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

  • New Member
  • *
  • Posts: 40
Re: Running Pascal applications in Android
« Reply #1 on: December 11, 2010, 12:00:45 pm »
Thank you.
This is an important beginning to understand actual FPC/Lazarus potentialities on Andorid.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Running Pascal applications in Android
« Reply #2 on: December 16, 2010, 06:25:04 pm »
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_Programming#Using_the_Android_API_from_Pascal

The full code is here:

http://p-tools.svn.sourceforge.net/viewvc/p-tools/PascalNotes4Android/

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Running Pascal applications in Android
« Reply #3 on: December 16, 2010, 11:49:19 pm »
:o 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

  • Full Member
  • ***
  • Posts: 102
Re: Running Pascal applications in Android
« Reply #4 on: December 17, 2010, 04:00:44 am »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Running Pascal applications in Android
« Reply #5 on: December 17, 2010, 10:24:10 am »
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?

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
« Last Edit: December 17, 2010, 10:31:11 am by felipemdc »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Running Pascal applications in Android
« Reply #6 on: December 17, 2010, 01:44:42 pm »
:o 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_Programming#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

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
Re: Running Pascal applications in Android
« Reply #7 on: January 02, 2011, 08:34:32 pm »
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

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: Running Pascal applications in Android
« Reply #8 on: January 10, 2011, 04:57:09 pm »
Is the Android a Google phone?

Android is a OS developed by Google, and used in some phones, tablets, etc.

/BlueIcaro

floydgonzales

  • Newbie
  • Posts: 1
Re: Running Pascal applications in Android
« Reply #9 on: January 12, 2011, 08:12:49 am »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Running Pascal applications in Android
« Reply #10 on: January 12, 2011, 03:42:35 pm »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Running Pascal applications in Android
« Reply #11 on: January 13, 2011, 12:09:51 pm »
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
« Last Edit: January 13, 2011, 12:16:43 pm by felipemdc »

laguna

  • Sr. Member
  • ****
  • Posts: 323
Re: Running Pascal applications in Android
« Reply #12 on: January 18, 2011, 08:30:53 am »
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?
« Last Edit: January 18, 2011, 09:12:09 am by laguna »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Running Pascal applications in Android
« Reply #13 on: January 18, 2011, 12:12:12 pm »
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

  • Sr. Member
  • ****
  • Posts: 323
Re: Running Pascal applications in Android
« Reply #14 on: January 18, 2011, 02:54:26 pm »
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.



 

TinyPortal © 2005-2018