I want to add a Run/Debug Configuration for an iOS Application for a Kotlin Multiplatform Mobile application in Android Studio 4.1.2. However, there seems to be a problem with the configuration for iOS.
In the screenshot below you can see the problem. In the dialog "Run/Debug Configuration" Android Studio complains about
Error: Please specify Xcode project location in xcodeproj property of gradle.properties
Using the "Fix" button does not solve the problem. Android Studio just adds an additional xcodeproj
to gradle.properties
and the complains about a duplicate parameter.
I also tried different paths (relative and absolute) for xcodeproj
. No luck.
If I remember correctly, it used to work out of the box. A new Kotlin Multiplatform Mobile project was automatically configured for Android and iOS. I'm not sure what changed. Probably something was updated.
Is this a bug with the KMM plugin? Or is there something I can do on my system to fix this?
With Kotlin Multiplatform, you can create different multiplatform projects for multiple platforms, including web, desktop, and other native platforms. Kotlin applications will work on different operating systems, such as macOS, Windows, Linux, Android, iOS, watchOS, and others.
Once you've made your Android application cross-platform, you can create an iOS application and reuse the shared business logic in it. Create an iOS project in Xcode. Connect the framework to your iOS project.
In Android Studio, select Settings/Preferences | Plugins, search Marketplace for Kotlin Multiplatform Mobile, and then install it. The Kotlin plugin should be compatible with the Kotlin Multiplatform Mobile plugin.
Platform-specific code is placed in platform-specific modules eg. ios, android and is used only by the specified platform. To use Kotlin multiplatform library in XCode or Android Studio project we have to build library files, for iOS .framework files are built and for Android .jar file is built.
Open the starter project in Android Studio 4.1 or later. Use a recent version of Kotlin — 1.4.20 or above. For iOS, you need Xcode 11.3 or later. Note: This tutorial assumes you are familiar with the basics of Android and Android Studio. If you are new to Android development, check out our Android Tutorial for Beginners series first.
In Android Studio, select File | New | New Project. Select Kotlin Multiplatform App in the list of project templates, and click Next. Specify a name for your first application, and click Next. In the iOS framework distribution list, select Regular framework. Keep the default names for the application and shared folders. Click Finish.
The shared module consists of three source sets: androidMain, commonMain, and iosMain. Source set is a Gradle concept for a number of files logically grouped together where each group has its own dependencies. In Kotlin Multiplatform, different source sets in a shared module can target different platforms.
don't do that with Android Studio.
Just open Xcode, click on 'open another project...', locate to the iosApp
folder that named it when creating your project on Android Studio.
after that, just click run and have fun.
If the project doesn't run right away even on opening it from Xcode and shows the shared framework is missing
, Then try generating the shared framework for iOS platform using terminal. Navigate to the project folder and execute
Command: ./gradlew packForXcode
Now the shared framework should have a xcode-frameworks
product and you should be able to build and run the project through Xcode.
I fixed it by downgrading the Kotlin version from 1.4.30 to 1.4.21. You can check this thread here. To downgrade, download the version you want from the plugin store and choose the install plugin from disk as in the picture below
Upgrading Android Studio version to 4.2.1, KMM plugin version to 0.2.6, creating new KMM project with KMM plugin, the problem can be fixed automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With