How to set up an Android development environment as an iOS developer?

August 25, 20215 min read#Mac, #Java, #BigSur, #Swift

Updated 16 Jan 2022: Another solution is described here

Updated 15 Jan 2022: I have updated the solution in a new blog post

If you are an iOS developer and want to kickstart your Android development learning journey, the first step would be creating development envrionment which includes at the minimum:

  • Java Runtime
  • Gradle
  • Android Studio IDE

For my goal, I’d also want to explore Kotlin Multiple Platform, therefore, I’ll also need some Java/Kotlin integration inside Xcode. Let’s explore how we can quick set all these tools up on a Mac.

The Problem

There are minimum dependencies for Android development that iOS developers might not be familiar with. On a fresh Mac Big Sur, Java is not instaled by default. There are multiple way to install Java on a Mac such as using SDKMan or jenv.

Although, Android Studio can automate many installation tasks such as the Android SDK and Emulators, there are still some manual configurations needed to be done in the system level so that the development envrionment works smoothly.

For my goal of exploring Kotlin Multiple Platform, I also need the integration of the above tools in a iOS project in Xcode.

The Solution

Since I have installed Ruby using renv, Pythong using pyenv, so I decided to install Java using jenv as well.

Install jenv

  • Install jenv using brew
brew install jenv
  • Open ~/.zshrc and add the following lines to the end of the file:
export JENV_ROOT=$HOME/.jenv
export PATH=$JENV_ROOT/bin:$PATH
eval "$(jenv init -)"
eval "$(jenv enable-plugin export)"

Install Gradle

Gradle is the build configuration tool for Android/Kotlin project

brew install gradle

Xcode Plugin for Kotlin

There is a plugin that helps writing and debugging Kotlin code directly in the Xcode. I haven’t tried it yet but you can take a look here for installation instructions

Testing

I have found some greate templates to start building Android and iOS apps sharing common KMP libraries. They have different levels of common stuffs, but serve the same purpose of having everything configured, so that we can start writing code without worrying about configurations. One thing I’ve recognised that all of them are using Cocoapods to integrate common KMP libraries into iOS apps.

PeopleInSpace Project

To test if everything works as expected, we will explore this Kotlin Multiple Platform repository: PeopleInSpace and try to compile and iOS version of the application

git clone https://github.com/joreilly/PeopleInSpace.git
cd PeopleInSpace/ios
pod install
open PeopleInSpaceSwiftUI.xcworkspace

Now you can start the application on simulator, you should be able to see the iOS app running on the simulator

people in space iOS app

If you get errors, you can try to open the Android project in Android Studio to check if you can run the Android project.

moko-template

Another greate Kotlin Multiple Platform template that I found is moko-template. We use similar steps to check if we run the app:

git clone https://github.com/icerockdev/moko-template
cd moko-template/ios-app
pod install
open ios-app.xcworkspace

news app

KaMPKit

Another template that you can use to kick start a KMP project is KaMPKit. And again, with the same steps we can start the iOS version of the app from Xcode

git clone https://github.com/touchlab/KaMPKit/
cd KaMPKit
./gradlew build
cd ios
pod install
open KaMPKitiOS.xcworkspace

iOS app

Conclusion

Here they are, the quick and simple steps to prepare yourself to explore Android and Kotlin development as an iOS developer.

All the steps are done on a fresh Big Sur installation. You’d probably it to adapt here and there if your system’s configuration is different.

I have shared some template projects that can be used to kickstart KMP projects quickly as well.

As I’m start learning Android/Kotlin as well, I’ll share my journey in the next blogs. See you next time 👋.

Quick Drop logo

Profile picture

Personal blog by An Tran. I'm focusing on creating useful apps.
#Swift #Kotlin #Mobile #MachineLearning #Minimalist


© An Tran - 2024