14

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

Jan Deinhard
  • 19,645
  • 24
  • 81
  • 137
  • 1
    Seems like this issue is trending. Duplicate of https://stackoverflow.com/questions/66113448/kotlin-multiplatform-mobile-unable-to-run-on-ios-execution-failed-for-task-sh?noredirect=1#comment116899426_66113448 and https://stackoverflow.com/questions/66055014/android-studio-adds-wrong-xcodeproj-location-in-kmp-kmm-kn and https://stackoverflow.com/questions/66113448/kotlin-multiplatform-mobile-unable-to-run-on-ios-execution-failed-for-task-sh#comment116896069_66113448 but no solutions yet – WhiteSpidy. Feb 09 '21 at 14:52
  • Ok, still good to know that this is not necessarily a problem with my system. I'm pretty sure it worked on my system a few days ago. – Jan Deinhard Feb 09 '21 at 15:03
  • I am pretty sure that it still works in my system. – WhiteSpidy. Feb 09 '21 at 15:04
  • I have already tried one of the project from the questions. I am pretty sure your's will work as well – WhiteSpidy. Feb 09 '21 at 15:06
  • Same here. Open `iosApp` project directly with xcode also cant run. Said cant load class `org.gradle.wrapper.GradleWrapperMain`, so I download `gradle-wrapper.jar` put it in `gradle/wrapper` dir , xcode work fine. But AndroidStudio still cant detect iosApp. – mixer Feb 10 '21 at 03:27
  • Got something :- https://youtrack.jetbrains.com/issue/KT-44805 – WhiteSpidy. Feb 10 '21 at 12:09
  • You are right. So it seems to be a bug that is related to something (a setting, a certain version, etc.) on the affected systems. One thing that comes to mind is, that I deleted some directories on my system: ~/.konan, ~/.gradle and ~/.android. Gradle downloaded a lot of packages again .. but maybe I removed something that could not recovered. Do you think that could cause such a problem? – Jan Deinhard Feb 10 '21 at 15:03
  • I just removed everything related to Android Studio from my system and re-installed. Same behavior. – Jan Deinhard Feb 10 '21 at 19:53
  • Take a look at this answer, can solve your problem: https://stackoverflow.com/a/67420945/187930 – ciccioska May 06 '21 at 15:12

5 Answers5

5

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

Hossein Badrnezhad
  • 424
  • 1
  • 6
  • 18
4

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.

iPP
  • 441
  • 1
  • 7
  • 12
  • Thanks, this workaround works for me until the bug in the plugin gets fixed. – Jan Deinhard Feb 26 '21 at 22:43
  • This works. Thanks for the solution. But I have to run this every time I change the code. It's like this on loop "code change in Android Studio > run this command > run app from Xcode" I was hoping if there is any alternative solution. – Danish Ansari Mar 06 '21 at 09:45
  • 2
    @DanishAnsari With the new release of KMM plugin this is solved I believe. I'm on AS canary release and latest KMM plugin, it doesn't have an issue. – iPP Mar 11 '21 at 11:45
  • @iPP yes I also noticed the same, thank you Though I got this error but fixed it as mentioned in the comments there https://youtrack.jetbrains.com/issue/KT-41691 – Danish Ansari Mar 13 '21 at 16:18
3

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

fidschau
  • 91
  • 1
  • 5
1

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.

yancaico
  • 1,145
  • 11
  • 21
0

If you don't wanna use Xcode:

Look like there is some IDE issues in this versions, one option would be to downgrade the Kotlin version.

What worked for me was to download the latest Canary Android Studio and setup my KMM project there.

Hopefully soon this will be stable for the next versions

Canato
  • 3,598
  • 5
  • 33
  • 57