Wednesday, December 29, 2010

Delphi for Android v0.3 Tutorial

Delphi Prism support iPhone and Android application development using Monotouch and MonoDroid where the goal of Delphi for Android ("Delphi Droid" for short) is to allow any developer that has Delphi 5 onwards to write Android applications.

This is a short tutorial on how to get started with Delphi Droid compiler version 0.3 as it currently is.

Note: The compiler isn't complete, there is still ALOT of work to be done. If you wish to help with the development, please contact me to contribute.

Requirements:
  • The Android SDK together with the Java SDK and Ant. Ant get used to compile the Android application since DelphiDroid generate a standard Android project (similar to how you do it using Eclipse)
  • Download DelphiDroid_v0.3.zip from the Google Code page.
  • Off course you need Delphi 5.0 or later.
  • .Net framework 3.5 run-time
What is in the ZIP:

Within the ZIP file you will find the following directories:
  • bin: There is where the compiler etc are located. You can set this as your SYTEM VARIABLE to call from command line.
  • DelphiDroid/DCCDroid: C# source code of the compile. This can be compiled using MS Visual Studio.Net 2008.
  • DelphiDroid/Framework: The "Delphi For Android" package that all Delphi applications require.
  • DelphiDTest: The Delphi example as in Sneak Preview 2 video.
  • Test: The actual Android projected generated by the compiler from the DelphiDTest example.
Setup Android SDK etc:

I'm not going to explain how to setup the Android SDK, I assume you already have knowledge on how to install the SDK, set it up etc.

Setup the compiler:

Within the bin folder you will find DCCDroid.exe.config file, open this using a plain text editor like Notepad:

  • Change the AndroidSDKDirectory to the location where you installed the Android SDK.
  • Change DelphiBinFolder to the location of the Delphi BIN folder that contains the Delphi compiler etc.
Run the sample program:

Open DelphiDTest and make sure it compile and run successfully in Delphi.

Run the compiler with no parameters:

Open the MS DOS Command prompt and run:

DCCDroid.exe

The output:

Delphi For Android 0.0.0.3 Dev Build
Copyright © 2010 by Lennie De Villiers

Invalid arguments, the following arguments are required:

Project Name - Name of the project
Activity Name - Name of the activity
Package Name - Java package name
Input Source Path - Delphi source directory path
Android Output Path - Android output directory path



So this is very basic command line parameters, i don't need to explain how they work.

You can open compile.bat file under the bin folder for an example:

dccdroid.exe DelphiAndroid DelphiAndroid com.test c:\Demo\DelphiDTest c:\Demo\Test
copy C:\Demo\bin\Android.Framework\*.* C:\Demo\Test\src\com\Test
cd c:\Demo\Test
ant debug

This will compile the example program (assuming the location like c:\Demo) , copy the Android libraries and compile the program.

When all is done you can run the run.bat file:

cd c:\Demo\Test\bin
adb shell rm /data/app/com.test.apk
adb -s emulator-5554 install DelphiAndroid-debug.apk

This will install the sample on the Android emulator.

You can look at compile.bat and run.bat to write your own compile/run scripts.

What is done:

Just like I said before, there is still ALOT of work to be done. Currently only the following components are supported:

TEdit
TLabel
TButton

References:


Mailing Lists:

Users:

http://groups.google.com/group/delphi-for-android-users

General users.

Developers:

http://groups.google.com/group/delphi-for-android-developers

Donations:

If you can't donate your time but wish to don't some money to help with the development, then please contact me.

6 comments:

호연 said...

oh, but it's already good, i can't wait anymore ;-)

호연 said...

Sorry...um..
ms -dos can't show the out put about dccdroid.exe....

Denis said...

Hi,

This project looks rather promising. My question is: does it support more advnaced things than simple win32-like UI? I am thinking of porting my old Pascal game to Android. I was using multiple sprites with transparency there. First I had it for DOS and later ported it to Delphi + DirectDraw. It was around 10k lines of code.
Do you think I could tweak the code to make it compilable for Android?

Thanks!

Android app development said...

Actually I am looking forward towards this kind of information.This is one of the wonderful post.
Android app developers

Ashraf_87 said...

when I move to this step
ant debug
it doesn't work
any suggestions ?

Lennie De Villiers said...

Please use the mailing lists for questions... Make sure that you installed Ant, that its on your path etc so that you can run Ant scripts successfully since Android SDK use Ant to build a Android application. If you don't know how this works then ask google since there are alot of tutorials online.