I had loaded the Android Development enviroment onto my PC around five years ealier, just to get a feel for what it was like. This time though I was going to port at App I have developed under Visual Studio in C# over to Kotlin to analyse the differences in ease of development, presentation on the Android devices and performance.
One huge difference between the two development environments is that C#/Xamarin/Visual Studio is a multi-platform environment, whereas the the Andriod SDK is solely Android.
Start of Process
First action was to download & install the latest version of the Android IDE. The version I downloaded is called Electric Eel and is available here. The download and installation process were a straigtforard as you would imagine. Process informed me there was an earlier version, and did I want to over-write it. Answer yes and all went smoothly.
I followed the ‘First Android Project’ tutorial here – which is to create what is termed the Greeting Card App. Followed the instrctions and then build the project, and that is where the configuration problems started.
Initial Configuration Issues
Problem 1 – No Device
Build goes fine. Deployment fails because there is no Android device selected to which the app could be deployed. Not that unreasonable, though I could have done with some warning from the tutorial. You have a choice of using a Virtual Device (emulator), or a phyical device – plugged in via USB (or even – thorectically at least – connected via WiFi).
I chose an emulator.
Problem 2- HAXM
Deployment then fails because the version of HAXM installed is out of date. OK – WTF is HAXM I hear you cry. HAXM stands for Hyper Accelerated Execution Manager. It is a peice of software released by Intel which, from the blurb, helps speed thing up when using Hyper Threading – or some such – but is hardware dependent.
The point is why should I be concerned about this. Either the installation of the Android SDK should highlight this requirement during installation, or it the SDK should walk you though installating HAXM, if necessary. Not just throw up a seemingless radom four letter Accronym and assume everyone knows what it is.
However, the SDK does provide a link to install the latest version of HAXM in the deployment error message – so I’ll give it that.
Duely click on the link. Installation duely fails. New link to web page where you can install manually.
Attempt to install manually, everything appears to conclude successfully, re-try build & deploy. Exactly the same problem.
Try a different emulator – went for an earlier model, a Pixel 2 instead of the Pixel 6. Did not fix the problem – but then I didn’t really think it would.
A search of the internet for solution didn’t really help much. Determined how to install latest version of HAXM, but the installation kept on failing. Eventually came to the conclusion that the best way forward was a complete uninstall and re-install, just in case the earlier version of either Android SDK or HAXM where the cause of the problem.
The uninstall and reinstall of Android was fine.
Uninstall of HAXM less so. You need to uninstall using Control Panel > Uninstall Programs. However HAXM is listed as Intel Hardware Accelerated Execution Manager. Once I had found it, uninstalled and re-installed problem solved.
Rebuilt program – fails compilation error. Wrong Gradle Version. At this point I am thinking, how can I have a compilation error with an empty project, and WTF is Gradle
Problem 3 – Gradle Wrong version
Gradle is what the Android SDK uses to build its programs – its basically a Make replacement. HOwever that still does not answer the question of why is it failing after having done a completely clean re-install.
The answer appears to be that the Android SDK, Kotlin and Gradle are all pretty fluid, and that the latest version of the SDK can use extensions in Kotlin that Gradle does not, by default, recognise.
The solution is to add the following lines to [Project]>app>src>build.gradle
Replacing ‘1.2.0-beta01’ with whatever Compose version is compatible with the version of Kotlin that you are using. How do you know which version of Kotlin you are using, well the Compiler Error message details that. For me it was 1.16.2
The list of compatible Composer : Kotlin versions is detailed here
After adding the above line am pleased to report that Project built successfully, and ran on both a Pixel 6 emulator and on a physical Motorola XT1068 connected via USB.