Learning Kotlin Multiplatform Mobile: Entry 1
Tags: kotlin, mobile, kmm
Published: 2022-06-01 23:15:17

So.... to force myself to not drop this project I am going to attempt to write my experiences while learning using [Kotlin Multiplatform Mobile](https://kotlinlang.org/lp/mobile/). My GitHub page is starting to become the place where ideas go to die 🫠. 


> Disclaimer, this is my first ever attempt at documenting really anything but lets get into it.
---

My interest for KMM has stemmed from working with Xamarin Forms. The code sharing is amazing and I absolutely love C# but if you need to add any frills or flair to your UI, well, you better buckle up and start creating those custom renderers 🚧.

Things that interested me about KMM:

```
1. Code sharing so you only have to write core code once.

2. Ability to use native cutting edge tech like Jetpack Compose and SwiftUI

3. You can quickly write native code if you need to get the job done. (Kotlin, Swift)
```

🎉 Here is my experience from 0 to setting up a new project:
`
TLDR: 8/10 experience. One minor issue while trying to run the iOS App which was quickly fixed searching stack overflow.
`
I pretty much followed the "Getting started" guide found [here](https://kotlinlang.org/docs/multiplatform-mobile-getting-started.html) word for word.

Step 1: 💻 Setting up my environment

- Straight forward enough here, I had already had android studio installed (Electric Eel canary build) on my machine with the Kotlin plugins/language pretty much up to date.

- I, however, had to install the Kotlin Multiplatform plugin for android studio.

![KMM Plugin installed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yizoo17hya8vpjl1y8u4.png)

Step 2: 📦 Creating the Project

- After installing the KMM plugin for android studio I followed the prompts to create a new KMM app and had it created and loaded in a quick minute.

![App creation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uy892347ro823s7tm8yd.png)

Step 3: 🤖 Running the Android app

- Easy as can be, waited for the Gradle sync and build to complete and just hit run in the upper right hand corner!


![Android app running fine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/npj2n9gbqji4yfseehwo.png)

Step 4: 🍎 Running the iOS App

- Now this one was a bit of a pain... When I first switched the configuration to "iosApp" I noticed a red X mark on the picture. After trying to run the app I was shown this error.

![ios red x mark](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cgx6ndr98lg9p2k87bfr.png)

![ios error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0p49h1xqk56y3t4jw6sy.png)

- I had to do some googling but this stack overflow post 
[here](https://stackoverflow.com/questions/71707858/getting-selected-scheme-iosapp-does-not-support-iphonesimulator-error-for) helped to solve the issue. 

- I closed Android studio and ran the following in my terminal and after that my simulator ran just fine.

```
cd ~/Library/LaunchAgents/
rm com.jetbrains.AppCode.BridgeService.plist
```

![ios app running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxxj3ltty7ikeaa8xqi8.png)

---

🎬 Final thoughts:
All in all it was a pretty straight forward experience with iOS being the problem child like it usually is. It is probably less buggy to run the iOS app directly from Xcode but the fix was not too bad. After the fix I was up and running exploring the project structure and generated code.

Next time I would like to see if I can get something small to work like creating a shared view model. My ultimate goals for the project is to get Firebase Authentication working for both apps and get the app communicating to a Ktor Kotlin backend api for sending and receiving chat messages.

Thanks for reading 👋 and hopefully this does not join the project graveyard anytime soon 🪦.