https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Azur Haljeta

11/18/2020, 3:08 PM
What do I need to do to have a KMM project working well with Xcode and cocoapods? I want to drop the
packForXcode
task and instead use cocoapods. And I also want to be able to add iOS-specific libraries directly into
build.gradle.kts
, like AFNetworking. I know that this is possible and doable but... Is there a complete example out there? I've tried the following but there ae always some issues...
- the
iosMain
directory is not treated as a source directory, which makes autocomplete or syntax highlighting impossible and hard to work with - renaming it to
iosX64Main
and tweaking the
build.gradle.kts
but this breaks metadata dependency resolving since there is no plain
ios
anymore
k

KamilH

11/18/2020, 3:10 PM
You most likely missing
Copy code
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
in
gradle.properties
a

Azur Haljeta

11/18/2020, 3:12 PM
thanks, but no - I already have this in
gradle.propeties
r

russhwolf

11/18/2020, 3:23 PM
Take a look at KaMPKit https://github.com/touchlab/KaMPKit We use a slightly more old-fashioned setup where we create either
iosX64
or
iosArm64
targets as needed, rather than using the
ios()
builder that uses heirarchical sources. See https://github.com/touchlab/KaMPKit/blob/master/shared/build.gradle.kts#L28-L33 If you are using
ios()
, I tend to find it works better in IDEA than Android Studio.
❤️ 1
a

Azur Haljeta

11/18/2020, 3:41 PM
@russhwolf thank you building the iOS app from Xcode now works, as well as the cocoapods integration somehow I'm still missing autocomplete and syntax highlighting features, even from
commonMain
. I encounter this pretty often in KMM. in the
build.gradle.kts
you've linked earlier, there is this comment:
Copy code
// Revert to just ios() when gradle plugin can properly resolve it
and the
if else
below distinguishes if Xcode wants to build the app on the simulator or on a real device? I'm coming from an Android background so this is somewhat strange to me at first
r

russhwolf

11/18/2020, 3:43 PM
yeah the if/else checks an environment variable that Xcode sets during its build, to decide which target to use
🙌 1
If you're still having trouble with autocomplete and highlighting, check your Kotlin IDE plugin version and make sure it matches the Kotlin version you're using in the project
a

Azur Haljeta

11/18/2020, 5:17 PM
Well, after hours of struggle, it seems that ktor client versions of
1.4.1
and
1.4.2
mess up the autocomplete feature in all sourcesets While
1.4.0
works fine