Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Expert Delphi

You're reading from   Expert Delphi Robust and fast cross-platform application development

Arrow left icon
Product type Paperback
Published in Jun 2017
Publisher Packt
ISBN-13 9781786460165
Length 506 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Paweł Głowacki Paweł Głowacki
Author Profile Icon Paweł Głowacki
Paweł Głowacki
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Fasten Your Seat Belts FREE CHAPTER 2. Mind Your Language 3. Packing Up Your Toolbox 4. Playing with FireMonkey 5. FireMonkey in 3D 6. Building User Interfaces with Style 7. Working with Mobile Operating System 8. Extending to the Internet of Things 9. Embedding Databases 10. Integrating with Web Services 11. Building Mobile Backends 12. App Deployment 13. The Road Ahead

Deploying to mobile devices

Our DelphiHelloWorld project is now ready for deployment to mobile devices. We have already built and run it on Windows. Now, we are going to first deploy it to an Android device and then to iOS.

This is a one-time preparation for mobile development that you need to go through after Delphi is installed. We want to get to the point that you can see your devices as targets inside the Project Manager.

For Android, all steps to configure your system to detect your device are described at http://docwiki.embarcadero.com/RADStudio/en/Configuring_Your_System_to_Detect_Your_Android_Device.

Deploying to Android

Deploying apps from Delphi to Android devices is simpler then deploying to iOS. You only need to have an Android device and a USB cable to connect your device to a Windows machine where you have Delphi installed.

Before deploying to an Android device, you need to find out if your device is supported by the version of Delphi you are using. For details, consult http://docwiki.embarcadero.com/RADStudio/en/Android_Devices_Supported_for_Application_Development for the list of currently supported Android versions.

The first step is to enable USB debugging on the device. This option can be set in Developer options on your device. This option is not easy to find. It is, in fact, hidden. On your Android device, go to the Settings | About menu. Tap the Build number seven times to make Settings | Developer options available. Then, check the USB Debugging option. Connect your Android device with a USB cable to a computer where your PC is running. If you are using VMware make sure that your Android device is connected to the virtual machine where you have Delphi and not to your Mac. The first time you connect your Android device, you may see a message displayed on the device to Allow USB debugging from the computer, identified by a string of hexadecimal numbers that represents the computer's RSA key fingerprint. Check the Always allow from this computer option and click on OK.

More info on enabling USB debugging on Android devices is available at http://docwiki.embarcadero.com/RADStudio/en/Enabling_USB_Debugging_on_an_Android_Device.

The next step is to install the USB driver for your Android device on the machine where Delphi is installed. The test device that I'm using is Google Nexus 7.

Probably the easiest option to download all the necessary bits for Android development is to download and install Android Studio for free from Google. It will download all necessary Java SDKs and tools that are needed in order to build an Android apk executable file. For reference, I'm using Android Studio version 2.2.2. On the splash, select the Android SDK option. In the dialog, select the SDK Tools tab and check the Google USB Driver option. Click OK and the driver will be downloaded and installed, as shown in the following screenshot:

Android SDK Tools with the "Google USB Driver" option checked

In order to make sure that the device driver has been installed successfully, go to the Device Manager window in Control Panel and you should find your device listed. If you right-click on the device, there is an option to Update Device Driver. I could find my Nexus 7 listed there and the device driver was up to date. Refer to the following screenshot:

Nexus 7 in Device Manager

Depending on your device, the steps may be different. You can find detailed information on how to install the USB driver for your Android device at http://docwiki.embarcadero.com/RADStudio/en/Installing_the_USB_Driver_for_Your_Android_Device.

Now, back to Delphi IDE. Make sure that our DelphiHelloWorld project is still open in the IDE. In the Project Manager, expand Target Platforms and click on Android. The first time you click on the Target node, you will see the message Android SDK tools are required. Do you want to download and install Android SDK tools automatically?. Click on Yes. The process to download and install SDK tools will start and you will see in the Command Prompt window the progress of the operation. After a moment, you should see your device listed under Tools in the Project Manager.

Double-click on the Android node to select the Android target. It should display in bold font. Now this is the current target, so when you click on the Run green arrow, the IDE will build our Delphi Hello World app using the Delphi Android compiler and the executable apk Android file will be created, deployed to the device, and run in just one operation.

Click on Run. The project will be compiled, deployed to your Android device, and run:

Delphi "Hello World" app running on Android

You can find more information about preparing your IDE for running apps on Android devices on DocWiki at http://docwiki.embarcadero.com/RADStudio/en/Android_Mobile_Application_Development.

Deploying to iOS

Deploying apps from Delphi to an iOS device requires a Mac computer. As compared to Android, deploying to iOS requires more steps because you also need to enroll for the Apple iOS Developer Program and to provision the device you want to deploy to.

First, you need to make sure that the iOS device that you want to deploy your application to is compatible. In case of iPhone, the oldest supported model is 4GS, but you want to have a device that can have iOS 10 installed. In my case, it is iPhone 6S.

The first steps to prepare your Mac and an iOS device for deployment are exactly the same that any iOS developer needs to do. This is something that you do once. During the process of deploying to an iOS device, an app needs to be digitally signed with the special command-line tool that comes with Apple Xcode installation. You could install just the Xcode command-line tools, but in practice it is easier to install the whole Xcode development environment from Apple.

In order to be able to deploy apps to an iOS device, it needs to be provisioned first. The process of provisioning iOS devices, joining the Apple iOS Developer Program, and installing various certificates is the same as in the case of any app developed with Xcode. In order to be sure that you will be able to deploy an app from Delphi into iOS, it is recommended to create an empty app from a template in Xcode and try to run it on the device. If this is successful, the next step is to install a special PAServer Mac program on the machine where you have Xcode installed. The PAServer19.0.pkg installable package is installed in the PAServer subdirectory of Delphi. Just copy it over to your Mac and execute. This will install the PAServer. The PAServer is implemented as a command-line app, and after it is launched on Mac, it will display a command-line interface where you will be prompted to enter your Mac password. Your Mac will also display a dialog asking if it is OK to give PAServer debugging permissions. Accept it.

You can think about the PAServer as an agent that performs operations on behalf of the Delphi IDE that runs on a remote Windows machine. In order for Delphi to be able to connect, you need to know the IP address of the machine where the PAServer is running. You can find out the IP address by issuing the i command from the PAServer's Command Prompt. The list of all available command-line parameters to PAServer is displayed when you enter ? in the Command Prompt, as shown in the following screenshot:

PAServer running on Mac

Now we need to configure Delphi, so it can find the iOS device you want to deploy to. The goal is to find your device listed in the Project Manager. In general, you could have multiple different Macs visible to your Delphi installation. For every Mac you want to deploy to, you need to define a connection profile.

Make sure that our DelphiHelloWorld project is open in the IDE.

Double-click on the iOS Device - 64 bit node under Target to make it active. It will be displayed in bold. Now, right-click on the node and select Properties. You will see a small Platform Properties dialog where you will be able to select the proper iOS SDK. Click on the SDK combo box and select Add New... from the dropdown.

Then, select Add New from the connection profile combo. The Create a Connection Profile wizard will be displayed. I have entered DelphiDev as the profile name. Click on Next. On the next tab of the wizard dialog, we need to enter the address and port of the remote machine. Keep the default port 64211 and enter your Mac password in the last field. Now click on the Test Connection button to verify that the IDE can communicate with the remote PAServer. If everything went well you should see the message that the connection to your Mac succeeded. Click on Finish, as shown in the following screenshot:

"Create a Connection Profile" dialog

Now, back in the Add a New SDK dialog, select the SDK version to add and click on OK:

Add a New SDK dialog

This will initiate the process of updating the local file cache, with files being downloaded from Mac that are needed by the Delphi iOS compiler to generate an iOS executable file. Refer to the following screenshot:

Updating Local Cache

After the cache is refreshed, the IDE should automatically update the iOS 64-bit Target node and you should see your device listed there:

Project Manager with an iPhone device listed as a target

Now click on the Run button. This will locally build the iOS ipa executable file and send it to the Mac machine where PAServer is running. The PAServer will invoke the command-line tool from the Xcode installation to digitally sign the executable, and then it will be deployed and run on the physical iOS device--all in one operation.

And here is how our Delphi Hello World app looks on my iPhone 6 running iOS 10:

Delphi "Hello World" app running on iOS

More information about deploying apps to iOS devices from Delphi can be found online at http://docwiki.embarcadero.com/RADStudio/en/IOS_Mobile_Application_Development.

You have been reading a chapter from
Expert Delphi
Published in: Jun 2017
Publisher: Packt
ISBN-13: 9781786460165
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime