Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure an iOS Application for Kotlin Multiplatform in Android Studio?

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?

enter image description here

like image 637
Jan Deinhard Avatar asked Feb 09 '21 11:02

Jan Deinhard


People also ask

How does Kotlin multiplatform work on iOS?

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.

Can I create iOS app using Android Studio?

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.

How do I set up Kotlin multiplatform?

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.

How to use Kotlin multiplatform library in Xcode or Android Studio?

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.

How do I start Android development with Kotlin?

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.

How do I create a multi platform app in Android Studio?

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.

What is shared module in Kotlin multiplatform?

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.


Video Answer


4 Answers

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.

enter image description here

like image 108
Hossein Badrnezhad Avatar answered Oct 26 '22 18:10

Hossein Badrnezhad


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.

like image 31
iPP Avatar answered Oct 26 '22 18:10

iPP


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 install plugin from disc screenshot

like image 3
fidschau Avatar answered Oct 26 '22 18:10

fidschau


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.

like image 1
yancaico Avatar answered Oct 26 '22 18:10

yancaico