Can I use a Kotlin Multiplatform Fleet project in Android Studio and Xcode? And how can I add a new multiplatform module?

Erick Medina
5 min readMar 30, 2024

Spoiler: Yes you can! In this article we’ll show you how to use alternately Fleet and Android Studio plus XCode, and how to get the best of them independently.

Recently I created a brand new Kotlin Multiplatform (KMP)using the KMP wizard, which is the de-facto way to start a new project using Fleet. Even though Fleet is in a public preview stage and with the free version we have exciting features like launching the app to iOS without XCode, there are many missing features to extend our project.

As you might know, when we create a new project with the wizard that targets Android and iOS (with Compose Multiplatform), we get a code structure with a module composeApp which in turn contains the source directories androidMain, commonMain and iosMain. The only other module that the project has is iosApp which is (as it name states) the iOS app with Swift components and its characteristic xcproject file.

Project structure view in Fleet IDE

So, we can consider both modules as UI modules and for my specific case I wanted to add a new multiplatform module which contains an external communications library. I didn’t want to have a direct dependency of the UI modules to that library. Sadly, Fleet as of version 1.32, doesn’t let you add a new module, only lets you add new files or folders and I had to find a way around.

Obvious solution was to use Android Studio (AS) but there was a compatibility issue. The AS version I was using to work with KMP previously was Giraffe 2022.3.1 Patch 4, but when you open the KMP project into it, we have a compatibility issue regarding the Android Gradle plugin version.

AGP compatibility issue with Andriod Studio Giraffe

That’s when I went to my current AS version which is Hedgehog 2023.1.1 but when tried to install the KMP plugin it wasn’t allowed because the latest plugin supported version was Giraffe.

Happily I found a Kotlin multiplatform plugin compatible version in the JetBrains marketplace which for some strange reason wasn’t appearing as available directly in the Hedgehog version of the IDE. I downloaded the 0.8.2 Hedgehog compatible plugin and installed directly in AS from disk.

Once the plugin is installed and the IDE is restarted, we are able to import the project into Android Studio. We open the project at the root directory and we have it available as if it were a native Android project.

Project structure view in Android Studio IDE

In Android Studio we don’t have the possibility to launch the iOS app, so we need to open it with XCode. Fastest way is to launch it directly from within AS by right clicking the xcodeproj file and open it in XCode. Remember that the prerequisites are that you run this on a Mac machine and that you have XCode already setup.

Launching XCode from Android Studio

If you can’t do it from AS, then just open XCode directly and open from within it the xcodeproject file of the iosApp project module.

Now, from XCode we are able to launch the app to the simulators or a real device. The structure of the iOS app looks like this:

Project structure in XCode

Adding a new module

Going back to Android Studio, we are ready to add a new module, which was the initial mission of this article. We choose to create a new Kotlin Multiplatform shared module called sharedLibrary.

Wizard for adding a new module

Now our project structure look like this with the new module:

Project structure in AS with new shared module

Since sharedLibrary is meant to be a library to be used by the composeApp, we add it as a dependency in the module’s build.gradle file.

composeApp module’s dependencies

After a new gradle build, we are able to use the code of the sharedLibrary module in the composeApp module.

OK perfect, but I do miss Fleet, so is this change compatible with Fleet?

Yes it does! You can open the project back in Fleet and you’ll have the new structure there!

Project structure in Fleet with the new shared module

You’ll be able to use Fleet again to edit the Swift code and launch the iOS app to the simulator/device all in one IDE withour alternating between Android Studio and XCode.

Good news is you can alternate the use of the IDEs and get the best of them. Another important scenario is to use Android Studio for the composable previews, which are not available in Fleet yet.

Thanks for reading up to this point. I hope this article has helped you to clear some doubts about Fleet and Android Studio plus Xcode.

--

--

No responses yet