Getting… rid of those red underline errors on your KMP project (iOS)

Carlos Mota
2 min readApr 4, 2022
Getting… rid of those red underline errors on your KMP project (iOS) cover

This is a really short article, but I’ve noticed in a couple of projects, that the platform-specific folder for iOS is unable to identify the imports of the platform package that contains the SDK.

Something similar to:

This can easily be resolved, by adding to your project gradle.properties file the following attributes:

#MPP
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
kotlin.mpp.enableCInteropCommonization=true

This results on:

Which allows you to navigate into the UIDevice class.

It’s also worth mentioning that with the latest release of the KMM plugin, when you create a project from the KMM template, these attributes are already set.

Kotlin 1.6.20-M1

Starting on Kotlin 1.6.20-M1 and upwards, the attributes:
- enableGranularSourceSetsMetadata
- enableDependencyPropagation

are automatically set. When you update to this new Kotlin version, you’ll see the following warning when compiling the project:

The property ‘kotlin.mpp.enableGranularSourceSetsMetadata=true’ has no effect in this and…

--

--

Carlos Mota

👨‍💻, 🔭🌖, 🗺, 📸, 🏃‍💨, 🇵🇹, 🖖 - is this how I should use emojis? Also: https://www.cafonsomota.xyz/