https://kotlinlang.org logo
Title
d

Daniele B

08/07/2020, 1:15 PM
I have a question about platform-specific libraries. For example Ktor. Let’s say, I use Ktor only in the shared project. And the shared project just has “CommonMain”. So, it doesn’t have neither “AndroidMain” nor “IosMain”. All the shared code is written in CommonMain and it’s perfectly compatible for both. There is not expect/actual implementation. In such case, do I still need to add platform-specific libraries such as “io.ktor:ktor-client-core-jvm”. And considering “AndroidMain” doesn’t exist, should I add it in “CommonMain” sourceset?
r

russhwolf

08/07/2020, 1:30 PM
Even if all your code is in common, you still need to explicitly declare what targets to build for. And those come with source-sets you can declare dependencies for, even if you don't have any code in them.
d

Daniele B

08/07/2020, 2:04 PM
@russhwolf thanks! so are “androidMain” and “iosMain” predefined keywords?
otherwise how does Gradle know that androidMain refers to the Android build, and iosMain refers to the ios build?
r

russhwolf

08/07/2020, 2:05 PM
It's generated from the target name. When you do
android()
, that's implicitly
android("android")
, and that creates an
androidMain
source. You could also do
android("foo")
and get
fooMain
instead.
d

Daniele B

08/07/2020, 2:06 PM
ok, I see, thanks!