Hi there! I use kotlin.cocoapods plugin to import ...
# ios
r
Hi there! I use kotlin.cocoapods plugin to import my shared code into my ios project (as described here https://github.com/JetBrains/kotlin-native/blob/master/COCOAPODS.md). My script_phases section in .podspec file:
Copy code
spec.script_phases = [
    {
        :name => 'Build multiplatform',
        :execution_position => :before_compile,
        :shell_path => '/bin/sh',
        :script => <<-SCRIPT
            set -ev
            REPO_ROOT="$PODS_TARGET_SRCROOT"
            "$REPO_ROOT/../gradlew" -p "$REPO_ROOT" :multiplatform:syncFramework \
                -Pkotlin.native.cocoapods.target=$KOTLIN_TARGET \
                -Pkotlin.native.cocoapods.configuration=RELEASE \
                -Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS" \
                -Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS" \
                -Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS"
        SCRIPT
    }
]
When I build my ios project it runs
syncFramework
task and I don’t understand how syncFramework works. Here are few examples: 1. I add some
println("")
inside a SharedCode function and when I build ios project the
syncFramework
does nothing. (I don’t see my println at runtime) 2. I change some function name
fun test()
->
fun myTest()
then Xcode says
test()
func isn’t exist and if I change it to
myTest()
it compiles and crushes at runtime with
unrecognized selector sent to instance
For now the only way to rebuild all the project it to delete the build folder from SharedCode and run Xcode build again. Does it work as expected?
m
the
syncFramework
task basically make a copy of the produced framework on your KMP module build folder to the Pod local framework folder
when you build your KMP library, an Apple framework is produced in the module's build folder...
the
syncFramework
task is added as a build step in XCode for the Pod that represents your library....
r
When I delete KMP build folder and run Xcode build the build folder (with Apple framework) will be created during the build. Who exactly will compile the framework?
m
the
syncFramework
task depends on
build
task in gradle
so, If the KMP is not built yet, the
build
will runs before the
syncFramework
r
Ok. What if KMP was built already. Does the
build
task understand that code was changed and it should recompile the framework ?
m
well, is that what is expected, but I always build my KMP module by hand when I change any code on it
and then I go to XCode...
r
Got it. I want to reach the flow: I start build in Xcode.
build
task sees the code was changed and recompile it (or just uses existed code if wasn’t changed)
m
flow =
XCode build
->
KMP Pod build
->
syncFramework
->
KMP Lib build in gradle
(if not already build)
r
Yeah. But I want the flow =
Xcode build
->
KMP Pod build
->
syncFramework
->
KMP Lib build in gradle
(if not already built or my KMP code has any changes since last build)
m
👍