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

Nikolai

11/08/2018, 4:37 AM
Hello, everyone Maybe silly question but I am not very familiar with Gradle. I am using IDEA, selecting : new project - kotlin- mobile shared library. Because according to description this type of project allow to share code between jam/Android and Native. At the start ide create to targets : iOS and jvm, it’s okay, but I want to use Android classes in jvm module (like SharedPreferances) to implement platform specific solution. But I can’t do it. How I can achieve it? I saw different projects that implement such behavior, but they use different project structure, I don’t really understand how to apply it here. I rad docs about multi platform projects on kotlinlang.org and found that they have different target types, including ‘android’. But when I try to add new target using : ’fromPreset(presets.android, ‘library’)’ I got error : ’Extension with name ‘android’ does not exist.’. I tried to follow this error and tried to solve it (adding gradle plugin, setting up different keys and sections in build.gradle file), but it always lead to kind of chaos in project at the end and I still can’t use android classes in jvmModule. Can someone please explain me how I can use android classes to implement platform specific implementation of common module? I put project what IDEA created here, in case you will need to see sources (https://github.com/nbaklanov-issart/multiplatform-prg-example). What I need to do? Add another target? Or depency? Or something else.
g

gildor

11/08/2018, 5:18 AM
but I want to use Android classes in jvm module (like SharedPreferances) to implement platform specific solution.
But you cannot use Android specific classes on JVM or common module, this is Android only code, so you have to abstract them For Android you need real android project with Android gradle plugin
You can check official examples to see how to configure Android as one of platfroms https://github.com/h0tk3y/k-new-mpp-samples
n

Nikolai

11/08/2018, 5:28 AM
Ok, thank you for explanations. I will take a look provided examples.