I have a project with a similar structure as the e...
# compose-ios
m
I have a project with a similar structure as the experimental falling-balls-mpp example from Jetbrains. Now I would like to add two native libraries (.dylib compiled from the same sources) one for macOS and one for iOS. I got that working already for macOS but not for iOS. Can anybody tell me into which project folder(s) I have to place these libraries so that they are correctly bundled with the iOS application and what search path I have to specify for the linker options?
n
As far as I know iOS prohibits .dylibs and you should use static linking instead. I will examine the issue and will follow up you
m
Ahh, I found this: https://developer.apple.com/forums/thread/125796 which suggest that .dylibs must be wrapped in a framework. I have no idea though how to do that in a project setup like the one mentioned above where I am not dealing with Xcode directly and the xcode project is automatically regenerated by the gradle script.
d
Recently, we updated falling-balls example, and now it includes Xcode project https://github.com/JetBrains/compose-jb/tree/master/experimental/examples/falling-balls-mpp/iosApp
n
@Michael Paus Now falling-balls example follows Kotlin Multiplatform project structure with CocoaPods dependency manager for iOS dependencies. Have you checked this -- https://kotlinlang.org/docs/multiplatform-mobile-ios-dependencies.html#with-cocoapods ? Does it work for you?
m
Many thanks @Dima Avdeev and @Nikita Lipsky. That sounds super interesting for various other reasons too. I haven’t checked it yet but I will do so over the weekend.
Well, I was not super successful on this. I freshly cloned the GitHub repository (just in case) and opened the experimental falling-balls-mpp example without changing a single character. The only thing I got was:
Copy code
Execution failed for task ':commonizeNativeDistribution'.
> Could not resolve all files for configuration ':kotlinKlibCommonizerClasspath'.
   > Cannot resolve external dependency org.jetbrains.kotlin:kotlin-klib-commonizer-embeddable:1.7.20 because no repositories are defined.
     Required by:
         project :

Possible solution:
 - Declare repository providing the artifact, see the documentation at <https://docs.gradle.org/current/userguide/declaring_repositories.html>
Before I start to fiddle around with it I thought I better ask here. I used
Copy code
IntelliJ IDEA 2022.3 (Community Edition)
Build #IC-223.7571.182, built on November 29, 2022
on an Intel Mac.
d
First, you need to install cocoapods (
brew install cocoapods
) The easiest way to run is to use AppCode or AndroidStudio with KMM plugin, as described in README. But, also you can use Xcode. • open project in Idea, link build.gradle.kts and sync gradle • go to
iosApp
dir in terminal •
pod install
open FallingBalls.xcworkspace
• Run on simulator or device
In the future, we want to use this project structure for all samples. It's easier to configure iOS specific part settings in Xcode. And it will be possible to debug in AppCode or AndroidStudio with KMM plugin in the future (for now, debugging is still not work for Composable functions)
The previous way to launch iOS samples with ./gradlew deployIPhone8Debug may be deprecated. We don't decide it yet.
m
According to the README links I have installed cocoapods already via
Copy code
sudo gem install cocoapods
and
Copy code
% which pod
/usr/local/bin/pod
shows where it is installed. I also have AndroidStudio with the KMM plugin installed
Copy code
Android Studio Flamingo | 2022.2.1 Canary 9
Build #AI-222.4345.14.2221.9321504, built on November 22, 2022
Kotlin Multiplatform Mobile
Jetbrains 0.5.1(222)-30
but the error message in AndroidStudio is exactly the same as above when I just open the project. Are there still some more manual configuration steps necessary? I also doubt that the “commonizer”-problem has anything to do with cocoapods.
d
I am using AndroidStudio 2021.3.1 Patch 1 with KMM plugin 0.5.1. But I think it should work with 2022.2.1 Canary 9 too.
I think it's Gradle related problem
What version of MacOS do you have?
m
MacOS Monterey 12.6.1
d
I have the same
Can you please try this instruction: • open project in Idea, link build.gradle.kts and sync gradle • go to
iosApp
dir in terminal •
pod install
open FallingBalls.xcworkspace
• Run on simulator or device
m
Just tried
Copy code
Android Studio Dolphin | 2021.3.1 Patch 1
Build #AI-213.7172.25.2113.9123335, built on September 30, 2022
Same error message.
What do you mean by “link build.gradle.kts”?
d
message has been deleted
m
Is this the context menu when you right-click on “build.gradle.kts”? If yes, then I don’t have such an entry in my context menu.
d
yes
It means, you already linked build.gradle
and may go to the next step
m
This resulted in
Copy code
mpaus@ip8-4 falling-balls-mpp % cd iosApp
mpaus@ip8-4 iosApp % pod install
Analyzing dependencies
Downloading dependencies
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
mpaus@ip8-4 iosApp % open FallingBalls.xcworkspace
mpaus@ip8-4 iosApp %
and opened XCode and I was able to build and run the example. This was the first time I ever had to use XCode 🙂 because I have never been an iOS developer although I own a Mac.
d
So, it works?
m
Yes, it worked but I just closed the project and also IntelliJ. After re-opening the project I got the same error message as before. Is this manual step always necessary after every restart?
d
You may use
pod-install
only for the first time of creating a project.
And not to close Xcode project
Thanks for testing our README doc. We will change it in the future for better understanding. And we will research this problem what you found with AndroidStudio part of our README.
m
Now you have me confused. What is the required procedure to re-open the already existing project?
And please keep the possibility “to launch iOS samples with ./gradlew deployIPhone8Debug” as an option. I really liked the possibility to work completely inside IntelliJ.
d
What is the required procedure to re-open the already existing project?
Just reopen FallingBalls.xcworkspace • from terminal with command
open FallingBalls.xcworkspace
• Or in Finder directory
./gradlew deployIPhone8Debug
we not decide yet, but we understand your interest, Thanks!
m
The original failure show above
Copy code
Execution failed for task ':commonizeNativeDistribution'.
> Could not resolve all files for configuration ':kotlinKlibCommonizerClasspath'.
   > Cannot resolve external dependency org.jetbrains.kotlin:kotlin-klib-commonizer-embeddable:1.7.20 because no repositories are defined.
is due to this declaration in the top-level build.gradle.kts file.
Copy code
subprojects {
    repositories {
        google()
        mavenCentral()
        maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
    }
}
If you move the inner part out of the subprojects block the build works and the commonizer dependency can be resolved. The tricky think is that if it was resolved once, the original declaration also does not produce an error anymore. Therefore you will probably not be able to reproduce this bug unless you completely empty all local gradle storage.
d
Very good research! Thanks!
I think the easiest solution is to change
subprojects {
to
allprojects {
We will change it
124 Views