How to begin lazarus / 43-Android ---------------------------------------------------------------------- eye · 2016-05-20 05:08 My programming experience was 20-25 years ago when i was studying and the language I used mostly was Pascal. The only experience I had was with Turbo Pascal for DOS and I was really good enough at programming (non commercial). Due to limited free time I didnt follow the changes so I have no programming experience after that period and no knowledge about modern programming languages. Now i have much more free time and decided to be involved at Android programming. To create some apps mainly for personal use so I learned the basics of Java and wrote few apps. The point is I dont like Java much and I feel much more comfortable programming at Pascal so I found that place. So my main question is should I prefer Pascal or should I try to be more familiar with Java since it is Android's main software programming tool? If you suggest me to use Pascal (which I prefer it a lot) then 1) Does this mean that I don't need Java at all or maybe part of program should be implement at Java? Can I call systems services, use device hardware within a Pascal program? 2) Is there any kind of tutorial-guide-documentation online that i could get some help? I am not talking about that installation guide but a guide-documentation on how to use Android's features 3) The quality of code that produced from a Pascal program is it better, worse or at same level than from Java ? I would appreciate a lot if you could help me ---------------------------------------------------------------------- JuhaManninen · 2016-05-20 08:43 I have not done Android programming with Pascal myself yet but I understood it is trickier than using a native compiler under Windows or Linux. It means you should first learn basics about FPC/Lazarus. Compile and study some examples etc. After you have an idea of what they can do then you can experiment with Android programming. Is Pascal recommended at all for Android? Somebody with more experience can answer that. ---------------------------------------------------------------------- Thaddy · 2016-05-20 09:06 Well, it all depends on your skills and what you want: For example, FPC has a pretty good back-end that generates jvm code for android. In that case you can leverage your Object Pascal skills to generate a jvm based Android program, just like with Java. But FPC also has a great ARM back-end that you can use to generate native code and interface with a jvm based front-end. As with almost any android environment: it takes some getting used to. I personally use the second option a lot: write high speed native code modules with fpc and interface with a jvm based front-end. ---------------------------------------------------------------------- Leledumbo · 2016-05-20 09:59 Quote from: eye on May 20, 2016, 07:08:39 amSo my main question is should I prefer Pascal or should I try to be more familiar with Java since it is Android's main software programming tool? Up to you Quote from: eye on May 20, 2016, 07:08:39 am1) Does this mean that I don't need Java at all or maybe part of program should be implement at Java? Can I call systems services, use device hardware within a Pascal program? Pure Pascal is possible, pure Java is possible, both working together is possible. Quote from: eye on May 20, 2016, 07:08:39 am2) Is there any kind of tutorial-guide-documentation online that i could get some help? I am not talking about that installation guide but a guide-documentation on how to use Android's features Not really if you want extensive documentation, the existing implementation is not even properly documented that it is usable by casual users. At least moderate knowledge of FPC is required, i.e.: understand how to build the whole compilation toolchain for any target from source. Quote from: eye on May 20, 2016, 07:08:39 am3) The quality of code that produced from a Pascal program is it better, worse or at same level than from Java ? Compiler dependent, case dependent. Oracle Java (HotSpot VM) has aggressive optimizations that can beat native languages in a tight loop or extensive numeric calculation. Other Java implementations might not. OTOH, in general Java applications run much slower than FPC applications (big memory usage might involve, because it can trigger OS to swap pages more frequently). This is however not really true for Android platform as since Android moves from Dalvik to ART, an AOT compiler already compiles Java bytecode into native binary at install time, so the performance should be similar with any native compiler. Quote from: eye on May 20, 2016, 07:08:39 amI would appreciate a lot if you could help me Study the basics first. Your existing knowledge might not be sufficient to do what you want. Read both official documentation and wiki, understand the examples and demos, make something simple and gradually improves it to something complex, etc. ---------------------------------------------------------------------- tintinux · 2016-05-20 12:08 Hi My opinion is that you can use Lazarus EDI to make Android packages with LAMW, it works globally fine, better and better, and the documentation is in progress, but it is not really stable and there are still a lot of traps. For user interfaces, you will have to use components rather different of those of the LCL for Windows,  Linux and OS/X. It is sometimes useful to read Java and Android documentation to understand things. However this is not worse than with C# in Visual studio, and even Java in Android Studio... Unfortunately CustomDrawn components, designed to be compatible with Android and many other systems and GUI, are not finished and AFAIK no more working on recent Android versions. May be this will change in the future, but there is a lot of work... For all other programming (not UI) you can program in Pascal and even share code written for other systems, the compatibility is very good and this is a good point.  Good luck ! ---------------------------------------------------------------------- Handoko · 2016-05-20 12:56 Quote from: eye on May 20, 2016, 07:08:39 amIf you suggest me to use Pascal (which I prefer it a lot) ... I don't mean to discourage or suggest you to use Pascal. You can easily find other software that can be used for Android programming. Here I just want to share my story. I don't make money from writing software. It's my hobby, so I prefer free tools. Pascal Language is my choice because it's easy to learn, fast and powerful. I ever tried Delphi, it's awesome. But it's too expensive, if I have commercial projects I may buy and use it. I found Lazarus / Free Pascal many years ago, and still playing with it now. The great is it's now can create Android applications. Unfortunately, it's still not mature enough in this Android programming area. As I remember, I started to learn Android programming using Lazarus a year ago. That was a really bad experience. Lack of documentations and buggy. After weeks of sleepless nights, I gave up. But I still came back often to this forum to see how the Lazarus - Android development progress. The default Lazarus installation can't produce Android application easily as you expected. You can't simply set an option box "Target OS to Android" and press the "Build" button then it's magically generate the result for you. You have to install Android SDK, NDK, and many tools. After them you still need to configure and cross compile your Lazarus/FPC. Cross compile was something new to me. I found the tutorial and do as it said. But no, it won't work as I thought. I had to learn line-by-line why I have to do as the tutorial said and adapted it to my case, and then it works. Recently, I managed to generate Android application. But honestly, there still something I'm not fully understand why I have to do this and that (as the tutorial said). That's okay, I'm happy now because I now can see my program running on my phone. But still as I mentioned it's not mature enough, there are many small bugs and things can be improved. So, you should tried other languages and/or tools before you decide to use one. If you google it, you can find that some of them are free. And if you're going to do for commercial projects, you may consider to buy the non-free and much mature one. Lazarus can be used for Android programming. But it's not painless: - Lack of documentation (this is the worst) - Need to install other things (CustomDrawn and/or LazToApk and/or Laz4Android and/or LAMW) - Need to manually cross compile the FPC - Many minor bugs and things to improve - Need to install Android SDK and NDK (both are easy) Good news is, Lazarus Android programming is improving. If you visit here often, you will see it becomes better every week. ---------------------------------------------------------------------- eye · 2016-05-20 20:44 Thanks for the answers. I really prefer to program at Pascal since I have a really very good background in that language but still dont understand how i am supposed to do it. I want to study and learn how to use it for android but what am i supposed to read? To be more specific as i mentioned at my first post I learned the basics of Java and wrote few apps. One of the was for my father to input his blood presure daily and keep the data to a file and to notify him each day at certain time to take his medicine. So I read the java-android documentation I found what kind of objects I needed  to get system time and date, which methods to use for writting to internal and external storage, how to use the AlarmManager etc. Where can i find such things if I need to implement same app in Pascal? This is my problem ---------------------------------------------------------------------- Handoko · 2016-05-21 04:17 Quote from: eye on May 20, 2016, 10:44:28 pm... So I read the java- android documentation I found what kind of objects I needed  to get system time and date, which methods to use for writting to internal and external storage, how to use the AlarmManager etc. Where can i find such things if I need to implement same app in Pascal? It should be doable. But ask it again if you've already has skill to create simple Android application able to create 'hello world' program that can run on your phone. Sorry to say so, because to start Lazarus Android programming is not as easy as you thought. The information are scattered here and there, you need to be diligent to collect and read them. For Pascal newbies, here are good places to start: http://www.pascal-programming.info/index.php http://www.taoyue.com/tutorials/pascal/index.html http://wiki.freepascal.org/Category:Tutorials http://wiki.freepascal.org/Lazarus_Documentation Bookmark these for references: http://www.freepascal.org/docs-html/ref/ref.html#refch3.html http://wiki.freepascal.org/LCL_Components http://www.marcocantu.com/epascal/English/default.htm http://www.pilotlogic.com/sitejoom/index.php/wiki/82-wiki/pascal- basics/162-pascal-basics-index If you already has good knowledge about Lazarus/FPC/Pascal, you can skip all those above and these below are Android related pages: Lazarus Android related wiki and sub forum: http://wiki.lazarus.freepascal.org/Portal:Android http://forum.lazarus.freepascal.org/index.php/board,43.0.html To be able to use Lazarus to build Android applications, you need to perform these things: - Install CustomDrawn and/or LazToApk and/or Laz4Android and/or LAMW) - Build your FPC to support cross compiling - Install Android SDK and NDK Here has the information about how to install LAMW, Android SDK & NDK and build your cross compiler: https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/readme_ get_start.txt https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/linux/n ew_how_to_install_by_renabor.txt http://wiki.freepascal.org/LAMW I use LAMW, this is my step-by-step to do to prepare my system (Linux only): Quote# Install Java, Android NDK/SDK and tools 01. sudo apt-get install android-tools-adb ant fp-compiler openjdk-7-jdk 02. sudo apt-get install subversion freeglut3 freeglut3-dev 03. sudo apt-get install libgtk2-gladexml-perl 04. sudo apt-get install libgtk2.0-bin libgtk2.0-cil libwxgtk2.8-0 05. mkdir ~/Android 06. Extract Android NDK https://developer.android.com/ndk/downloads to ~/Android 08. ln -sf ~/Android/android-ndk-r11c ~/Android/ndk 09. cd /usr/bin 10. sudo ln -sf ~/Android/ndk/toolchains/arm-linux- androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as arm-linux-androideabi-as 11. sudo ln -sf ~/Android/ndk/toolchains/arm-linux- androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld.bfd arm-linux-androideabi-ld 12. sudo ln -sf /usr/bin/arm-linux-androideabi-as arm-linux-as 13. sudo ln -sf /usr/bin/arm-linux-androideabi-ld arm-linux-ld 14. Extract Android SDK https://developer.android.com/sdk to ~/Android 15. ln -sf ~/Android/android-sdk-linux ~/Android/sdk 16. Install SDK Packages by running ~/Android/sdk/tools/android 17. Add to ~/.bashrc: export PATH=$PATH:~/Android/ndk/toolchains/arm- linux-androideabi-4.9/prebuilt/linux-x86_64/bin # Cross Compile Android ARM 01. cd /usr/share/fpcsrc/3.0.0 02. sudo make clean crossall OS_TARGET=android CPU_TARGET=arm 03. sudo make crossinstall OS_TARGET=android CPU_TARGET=arm INSTALL_PREFIX=/usr 04. sudo ln -sf /usr/lib/fpc/3.0.0/ppcrossarm /usr/bin/ppcrossarm 05. sudo ln -sf /usr/bin/ppcrossarm /usr/bin/ppcarm 06. Add these lines to /etc/fpc.cfg: ---------- #IFDEF ANDROID #IFDEF CPUARM -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/* -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl #ENDIF #ENDIF ---------- # Lazarus Android Module Wizard Installation 01. cd ~/Android 02. svn co https://github.com/jmpessoa/lazandroidmodulewizard.git 03. ln -sf ~/Android/lazandroidmodulewizard.git ~/Android/lazandroidmodulewizard 04. Start Lazarus IDE 05. menu > Package > Open Package (.lpk) > "tfpandroidbride_pack.lpk" 06. Compile, then and Use > Install 05. menu > Package > Open Package (.lpk) > "lazandroidwizardpack.lpk" 08. Compile, then and Use > Install 05. menu > Package > Open Package (.lpk) > "amw_ide_tools.lpk" (folder: ...\ide_toos) 10. Compile and Use > Install 11. menu > Tools > [Lamw] Android Module Wizard > Path Settings: ---------- Path to Java JDK: /usr/lib/jvm/java-7-openjdk-amd64 Path to Ant bin: /usr/bin Path to Android SDK: /home/handoko/Android/sdk Path to Android NDK: /home/handoko/Android/ndk NDK Version: 10c Select [prebuilt] System: Linux-x86 Resources: /home/handoko/Android/lazandroidmodulewizard/thrunk/java ---------- I think LazToApk + Laz4Android + CustomDrawn combination is much easier to start with, unfortunately it has bug that prevent me to use it. Here if you want to try: https://sourceforge.net/projects/laztoapk/ And don't forget to visit this forum and ask questions if you ever get problem.