If, for whatever reason, you want to set up the Android SDK/NDK (perhaps there was a failure during your Delphi install), the manual process can be a little involved. This article lays out the steps which includes using an AndroidSDKInstaller app that makes life a little easier.
In Case You Missed It
RAD Studio 10.4.1 has been released recently! I may do my own post about what is included, however I recommend checking the blog roll on the right hand side of this page, as well as your own favourite blogs and newsfeeds.
Jim McKeeth’s Android SDK/NDK article
Last year, Jim McKeeth wrote this excellent article which describes how to install the SDK/NDK manually, so you may wish to read that first, however there’s some manual steps that can be done via the command line that I’ve automated in the installer.
Install the JDK
As per Jim’s article, the first step is to install a JDK. You will need to install it in order for the AndroidSDKInstaller app to work, if you are going to use it. You can choose the AdoptOpenJDK, or you can still install the JDK from Oracle – please use the Windows installer for your system (x86 if 32-bit only, or x64 if 64-bit) at the bottom of the Java SE Development Kit section.
Using AndroidSDKInstaller
Once the JDK has been installed, you can use the AndroidSDKInstaller that has been built to ease the process of installing the Android SDK tools, build-tools and platforms. The installer has been purpose-built to provide the minimum required to use with Delphi.
When running the installer, click the Download button to download the SDK tools. I recommend creating a folder dedicated to where the SDK and NDK will end up being installed. In this example, I’ve created a folder called Android, and a subfolder called SDK where the SDK tools will be downloaded to, and also where the build-tools and platforms will be installed:
Once you’ve selected the SDK folder, the installer will then download and extract the SDK tools, and retrieve the packages available for install. The Select SDK button can be used in the case where you have an existing SDK, and just want to install extra build-tools and/or platforms.
Once the installer has retrieved the lists of packages, it will then look like this:
As can be seen, Platform Tools is checked by default – Delphi requires these in order to function. You have a choice of Build Tools and Platforms that you can install, however it is recommended just to install those that will work with your installed version of Delphi. In Delphi 10.4.x, I recommend using build-tools version 29.0.2, and platform android-29. Once you have selected the build-tools and platform, click the Install button:
The installer will inform you when it has finished. Click OK, then click Close
Installing the NDK
As per Jim’s article, the latest NDK can be downloaded from here, however it is recommended that you use a version that is known to work. In the case of Delphi 10.4, NDK version r21b is known to work. Older versions such as this one can be downloaded from here.
Following on from the example above, I recommend extracting the NDK to a folder called NDK, at the same level as the SDK:
Adding the SDK/NDK in Delphi
For this step, I’ll refer back to Jim’s original article, rather than just repeating it. Please see the section “Setting Up The IDE SDK Manager”, remembering where you installed the SDK/NDK as per the instructions above.
Important information about the NDK settings
If, like me, you happen to be targeting devices including those that have older versions of Android (some of them have Android 4.4!), you will need to make a couple of tweaks to the NDK settings. These are:
- NDK API Location
- C++ Builder NDK Library Path (not essential if you are not using C++ Builder, however included here for completeness)
- Delphi NDK Library Path
As per the following screenshot, I have changed the platform level for each of these settings to android-19. This is the lowest API level supported by the native code in the resulting Delphi application, and corresponds to Android 4.4:
A complete list of released Android versions and their API levels can be found here.
NOTE: Some functionality may not compile/link – this includes Datasnap (MIDAS) since the binaries are incompatible with lower versions of Android.
Conclusion
That should cover all of the steps. If I’ve missed anything, please let me know in the comments. Hopefully the AndroidSDKInstaller app makes this process a lot easier for you!
Absolutely use AdoptOpenJDK, not the Oracle version! You’ll have to pay big dollars to them.
ele não montou pra mim o Plataform Tools
Quer dizer que a pasta “platform-tools” não está presente na pasta SDK, após a instalação?
Thank you very much for the AndroidSDKInstaller app !!!
Obrigado pela ferramenta, mas fiz tudo que está aqui e não consegui por a funcionar no Android 5 algum sugestão para ajudar.
Could you clarify which version of the NDK to use with Delphi 10.4.2 please? r21b doesn’t exist on the download page
Hi Dave/All!
We are currently using Delphi 10.1 Berlin, is it possible to install an Android SDK version capable of building Apps for Android 11 (SDK 30) or would we need to update our Delphi IDE?
It depends on what aspects of Android 11 you need to support. I recommend using the latest versions of Delphi anyway, since they have built-in support for later versions of Android, and this can be vital if the apps are being deployed to Play Store.
Hi Dave!
When I build my project for Android get failed on this error:
[DCC Error] E2597 c:\\program files (x86)\\embarcadero\\studio\\23.0\\lib\\Android\\Release/libibtogo.a(eng_init.o):eng_init.c:function engine_unlocked_init: error: undefined reference to ‘__sync_fetch_and_add_4’
Can help me?
As per the article, there are some binaries in Delphi that are not compatible with lower API levels. If you have the NDK settings configured for API level 19 (Android 4.4), I assume libibtogo.a (which is used for Interbase To Go) is one of them. You would need to either not use Interbase To Go, or try a higher API level, such as 21 which is Android 5. Of course for the latter, it means your app will work only on devices with Android 5 or higher.
Nice info, thank you.