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
- 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.
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.
Since I have installed Ruby using renv, Pythong using pyenv, so I decided to install Java using jenv as well.
brew install jenv
~/.zshrcand 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)"
Gradle is the build configuration tool for Android/Kotlin project
brew install gradle
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
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.
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
If you get errors, you can try to open the Android project in Android Studio to check if you can run the Android project.
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
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
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 👋.