how to check if my library is platform independent...
# multiplatform
c
how to check if my library is platform independent?
m
At the moment I am not aware of any other method than to set up a multi-platform project with all existing targets, copy your code into commonMain and see if it compiles and runs. In practice you will have to reduce the number of targets to the ones that a really relevant for you because the majority of the existing external libraries, that you may reference in your code, don’t support all existing targets. @Mikolaj Why do you consider this question “NOT KOTLIN”?
m
Misunderstood the question, Your answer made it clear, taking it back 🙏 Still, every java library is platform-independent if you run on JVM 🤷‍♂️ I think "kmp compatible" would be the term to describe what OP wanted to check 😄 ... but that's picking on words - the question makes perfect sense on this channel 🙌
c
@Michael Paus I currently created a kmp library throught android studio plugin, But don't need android/ios ui.
I want a more general library for my kmp project that can be served for andorid / ios / desktop.
Can this be done through the plugin?
m
c
@Mikolaj I mean If I only need the commonMain, How to remove other modules out of my library and how to avoid platform dependent packages being included.
m
@calidion So the way multiplatform libraries work is you have to declare the targets in your
build.grade
(like androidTarget() and such). Declaring them creates the
sourcesets
bu you do not have to keep the directories for the sourcesets if they are empty (ergo all your code resides in
commonMain
). As for platform dependent packages, if You moved your code to
commonMain
and it does not compile (depends on some platform specific stuff) you have two options 1. Write expect/actual classes and provide implementation on each supported platform 2. Write your own implementation in commonMain
You can think of the
commonMain
sourceset as the wrapper/umbrella module for all the targets that your library support. It should contain the code that is common for all platforms.
Btw that is one of the main advantages of KMP. Distributng packages for each platform lets you use the multiplatform library (targeting for example JVM & Native) in JVM-only application. 🙌
c
seems kmp projects are controlled not just by gradle but the kmp plugin? I don't see configurations over the directories?
👌 1
m
c
OK. I would suggest that there can be a version that can help forge kotlin platform independent libraries (common libraries). and can be published like lib.kpi.crypto, libs.kpi.util, libs.kpi.image. which can be included into kmp easily.
I am currently developing a library, but I don't know if libraries I included are Platform independent.
m
I think the work is beeing done in that direction. Recently the cross-compilation of libraries was added, so now you can build ios libraries on linux machine. I think there also was some talk about it on last google i/o but I might be wrong 🤷
c
If there is a plugin can help, then I would save a lot of time before I really integrated them into platform dependent code.
m
I am currently developing a library, but I don't know if libraries I included are Platform independent.
You can just put your code in commonMain and if it lights up red then it is not platform independent 😇
c
Yes. I mean I don't need other folders and want to customize folder organization.