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

Peter Hsu

06/16/2020, 7:51 PM
Hi all, I have a general question about using libraries. I have a project that exports to iOS, Android, and JS. I needed to pull apollo-graphql into my project. Apollo-graphql only supports iOS and Android at this time. Since there is no JS support, I'm unable to add the library dependency to the "common" sourceSets, so I'm unable to share that work for iOS and Android within my project.. It seems like I could create a separate project/repository that exports the iOS/Android artifacts that I need, but that's pretty heavyweight. Is there a better way to accomplish what I want?
k

Kris Wong

06/16/2020, 7:54 PM
expect/actual a bridge API with an empty implementation for JS
p

Peter Hsu

06/16/2020, 8:04 PM
That's what I'm hoping to be able to do, but since I'm adding the apollo-graphql as a dependency to the sourceSets/commonMain, it's preventing JS from exporting
If I add it to sourceSets/androidMain and sourceSets/iosMain, then I wouldn't be able to share the code
seems like setting up a separate multiplatform module that exports to iOS/Android only is the way to go and to pull those dependencies into sourceSets/iosMain and sourceSets/androidMain
k

Kris Wong

06/16/2020, 8:27 PM
i'm not sure what you mean when you say you wouldn't be able to share the code. are the APIs exactly the same for the iOS and Android SDKs?
even if they were, which seems highly unlikely, the imports would be different
or is it a KMP library?
p

Peter Hsu

06/16/2020, 8:39 PM
it is a KMP library
k

Kris Wong

06/16/2020, 8:42 PM
gotcha
in that case I would create a
mobile
common source set, i.e.,
mobileMain
,
mobileTest
👍🏿 1
👏 1
p

Peter Hsu

06/16/2020, 8:46 PM
ok, that makes sense, thank you!
🍻 1