Android in Lazarus

download Android in Lazarus

of 20

  • date post

    29-Oct-2015
  • Category

    Documents

  • view

    768
  • download

    2

Embed Size (px)

description

Membuat aplikasi android dengan bahasa Pascal di Lazarus IDE.

Transcript of Android in Lazarus

  • Custom Drawn Interface/AndroidContents

    1 Architecture 2 Roadmap 3 Using the Android SDK, Emulator and Phones 4 Android Programming 5 Configuring the Free Pascal Compiler for Android

    o 5.1 Use the ready Virtual Box Image with FPC and Lazaruso 5.2 Building the compiler yourself in Windowso 5.3 Using the pre-compiled compiler in Windowso 5.4 Building the compiler yourself in Linuxo 5.5 Using the pre-compiled compiler in Linux

    6 Install the Java JDK and the Android SDK and NDK 7 Compiling the example LCL Android Application 8 How to create an LCL Android Application

    o 8.1 Step 1 - Creating the LPIo 8.2 Step 2 - Building the libraryo 8.3 Step 3 - Create the Android project structureo 8.4 Step 4 - Creating the APK package

    8.4.1 Step 4 - Creating the APK package in Linux 8.4.2 Step 4 - Creating the APK package in Windows

    o 8.5 Building an LCL Android application with debug info 9 Oh no! My LCL Android application doesn't work

    o 9.1 The Pascal executable was compiled for a wrong architecture, operating systemand/or widgetset

    o 9.2 My Pascal application crashed. How to get a stacktrace?o 9.3 The indispensable build optionso 9.4 Wrong package name

    10 Free Pascal Bugs on Android Supporto 10.1 FPC4Android Branches

    10.1.1 FPC4Android 2.5.1 10.1.2 FPC4Android 2.6.1

    11 Android SDK and NDK bugso 11.1 Android NDK for Windows broken linkero 11.2 Error while calling DX: Trouble processing: bad class file magic (cafebabe)

    12 Development Noteso 12.1 The mysterious JNI Crasho 12.2 NDK Libraries available in Android 2.2 (API level 8)o 12.3 Native text drawingo 12.4 Flood of garbage collector messages when the caret is visibleo 12.5 Why the caret of a TEdit keeps blinking after clicking on the formo 12.6 Android ComboBoxo 12.7 Using the Native ListView Dialogo 12.8 LazDeviceAPIs

  • ArchitectureLCL-CustomDrawn-Android utilizes a minimal Java application which communicates with our Pascallibrary and sends all events to it and also obeys commands from it. The communication is done via JNIas supported by Google. The controls are not native, instead they are all drawing usingTRawImage+TLazIntfImage+TLazCanvas and events and the painting are clipped using LazRegions.The drawing itself is done in Pascal using jnigraphics to draw on a Bitmap Java object which is thendrawn by the minimal Java activity on a SurfaceView.Our previous and short-lived attempt to write an LCL Interface for Android (LCL-Android) utilized anon-standard method of using native executables which communicated with a Java machine via Pipes.This method was abandoned because it was considered unsupported by Google. It is consideredobsolete and people should use LCL-CustomDrawn-Android instead. This older interface wasdocumented in Android Interface.

    RoadmapPart 1, until March 2012:

    1. Build the set of Lazarus Custom Drawn Controls2. Initial bindings for the Android APIs3. Create an application to automatically generate the bindings4. Start the new widgetset5. Implement support for JNI6. Merge the Lazarus Custom Drawn Controls into the LCL and use them to implement all basic

    controls7. Add text support for Android8. Implement basic window client area scrolling9. Add mobile emulator for desktop platforms10. Improve the mobile scrolling11. Add text support in X1112. Add DPI awareness and adaptation in the LCL13. Add non-native text support via pasfreetype

    Part 2: April, May, June 2012:1. TButton improve the Android visual2. TBitBtn3. TRadioButton finish the native look4. Calendar dialog -> Problematic as the LCL has no calendar dialog, it just opens a normal form

    and puts a calendar on it, so we need a TCDCalendar widget5. MaskEdit6. Improve TComboBox7. TMemo8. TListView as a list with columns9. TMainMenu10. Database with sqlite11. Barcode reading12. Windows add-on installer13.

  • Using the Android SDK, Emulator and PhonesCustom Drawn Interface/Using the Android SDK, Emulator and Phones

    Android ProgrammingConfiguring the Free Pascal Compiler for Android

    NOTE:The cross-compiler instructions below are probably obsolete, since support for the Android target ispresent in the trunk (development) version 2.7.1 of FPC. Here are up to date instructions: building across-compiler for Android target.

    Use the ready Virtual Box Image with FPC and LazarusThe fastest way to configure Free Pascal and Lazarus for Android development is simply using a pre-configured virtual machine image which already includes Mageia Linux 1, KDE, Lazarus 0.9.31,Subversion, Free Pascal for both x86-linux and arm-linux (targetting Android), the Android SDK, theAndroid NDK, Java, Ant, Gtk2 and all it's development packages, the GNU debugger (GDB),subversion and everything else necessary for building Android applications with Lazarus.The download like for the virtual machine image is: https://sourceforge.net/projects/p-tools/files/Lazarus_for_Android_VM_Image/snapshot_30_dez_2011/ (warning: the VirtualBox imagewas created using the Mac OS X default Zip utility and not all zip applications can handle it. The MacOS X default zip application can, and PeaZip too and WinRAR too. Both 7-Zip and the Windows 7default unzipper fail.The virtual machine image is composed by two files: Android Devel VM.vbox and Android DevelVM.hdd. Both need to be located in the same folder and also note that the source forge download is azipped file, so it needs to be unzipped. After unzipping the VM image has 5,2GB. To use this virtualmachine one should install Virtual Box and then use it to open the .vbox file. Then one can already usethis Linux virtual machine to build Android applications. The process of building an applicationinvolves first opening Lazarus and building the application in Lazarus, for example the example projectavailable on ~/Programas/lazarus/example/androidlcl/ and then going into the Linux terminal,navigating to ~/Programas/lazarus/example/androidlcl/android and issuing the command ant debugwhich will generate the APK file in ~/Programas/lazarus/example/androidlcl/android/bin/LCLExample-debug.apk. There are two users in the virtualmachine: root and pascaldev and both of them use the password root.Note that the virtual machine contains the Lazarus source code from when it was created, but one canalso use svn update to get the latest code. Note that this involves some risks, however, as the trunkversion might ocasionally contain problems.Building the compiler yourself in WindowsStep 1 - Install the Android SDK and NDKDownload from Google and install both the SDK and the NDK for Windows.

  • Check your path to the binutils installed by the NDK. For example, for NDK r7 installed inC:\Programas\android-ndk-r7\ the path is C:\Programas\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\binAlso check your path to the libraries installed by the NDK. For example, for NDK r7 installed inC:\Programas\android-ndk-r7\ the path is C:\Programas\android-ndk-r7\platforms\android-8\arch-arm\usrStep 2 - Download FPC 2.5.1 from January 19thCreate a folder to store the FPC trunk source code and checkout revision 16790Or if you want support for database and many other nice fixes use the branch fpc4android from here:svn co https://p-tools.svn.sourceforge.net/svnroot/p-tools/fpc4android fpc4androidStep 3 - Install FPC 2.4.4An easy way to obtain a good FPC 2.4.4 is installing Lazarus 0.9.30.2. For example, let's say you installthis Lazarus version in C:\Programas\lazarusfpc244Step 4 - Create the build script and built itCreate the output directory, for example: C:\Programas\fpcandroid\outputNext create a file called build.bat in the fpc root folder, in our example C:\Programas\fpcandroid andcopy to it:SET PATH=C:\Programas\lazarusfpc244\fpc\2.4.4\bin\i386-win32\make crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=C:\Programas\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin OPT=-dFPC_ARMELBINUTILSPREFIX=arm-linux-androideabi- INSTALL_PREFIX=C:\Programas\fpcandroid\outputpause

    Next run this batch script and you should have FPC installed into C:\Programas\fpcandroid\outputStep 5 - Copy some cross-binutils into the bin dirYou now should have a FPC binary in C:\Programas\fpcandroid\output\bin\i386-win32Now get these 3 files:C:\Programas\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin\arm-linux-androideabi-as.exe C:\Programas\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin\arm-linux-androideabi-ld.exe C:\Programas\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin\arm-linux-androideabi-strip.exeAnd copy and then rename to have:C:\Programas\fpcandroid\output\bin\i386-win32\arm-linux-as.exeC:\Programas\fpcandroid\output\bin\i386-win32\arm-linux-ld.exeC:\Programas\fpcandroid\output\bin\i386-win32\arm-linux-strip.exe

  • Step 6 - Merge this into a Lazarus FPC setupLet's say you have the following Lazarus C:\Programas\lazarus31 with the following fpc installed insideit: C:\Programas\lazarus31\fpc\2.6.1\bin\i386-win32 and C:\Programas\lazarus31\fpc\2.6.1\units\Now create a directory C:\Programas\lazarus31\fpc\2.5.1\units\arm-linux and copyC:\Programas\fpcandroid\output\units\arm-linux thereCopy all .exe files from C:\Programas\fpcandroid\output\bin\i386-win32\ intoC:\Programas\lazarus31\fpc\2.6.1\bin\i386-win32(! copy the exe-files to FPC 2.6.1 !)Now you can already build the example project androidlcltest.lpi using the Windows-Release buildmodeUsing the pre-compiled compiler in WindowsStep 1 - Download and unzip the pre-compiled compilerThe download is available here: https://sourceforge.net/projects/p-tools/files/Free%20Pascal%20for%20ARM/Windows/Step 2 - Merge it into the FPC installationLet's say you have the following Lazarus C:\Programas\lazarus31 with the following fpc installed insideit: C:\Programas\lazarus31\fpc\2.6.1\bin\i