Kotlin Multiplatform Project for Android and iOS: Getting Started | raywenderlich.com

In this tutorial, you’re going to see how to build an app for Android and iOS while only having to write the business logic once in Kotlin.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1022411-kotlin-multiplatform-project-for-android-and-ios-getting-started

Nice article! I was waiting one detailed article like this some time ago. However I still don’t understand the initial process of the setup of the project. Could you describe a little bit more about the steps to follow in order to get this configuration? It would be super helpful for me!

Thank you in advance.

@coletz Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi @itspecialists! If you’re using IntelliJ IDEA (which I recommend for any kotlin related project since the Community Edition is 100% free) you can get a pretty similar setup (everything is getting updated really quickly so maybe something can change) with the default project creation:

  • start IDEA, then File>New>Project and a popup will appear;
  • on the left panel select “Kotlin”, and the right panel will change
  • on the right panel select “Kotlin (Mobile Android/iOS)”
  • complete the setup with your project name and other stuff the wizard will ask you (project/sdk location, kotlin version, java version and so on)
  • Enjoy your brand new project, that’s it!

If you need help with something else don’t hesitate :]

Thank you very much for your response! I followed the steps:

So I first created a new project from Kotlin (Mobile Android/iOS) template. then clicked on next and the following configuration was like this: 1

After that, this error screen was displayed: 2

So I clicked on “Re-download dependencies and sync project” and the following appeared: 3

I clicked ok, but that didn’t fix the problem. And my build.gradle is showing this message: 4

I tried to hit “try again” but nothing happened, I’m not sure what I’m missing. I followed all the tutorial successfully.
Thanks for your time and your help, I really appreciate it!

Can you try to press on the “Ok, apply suggestion!” link above the “Try Again”? I never experienced this issue so I’m not sure on what’s the cause. I just created a new project with the IntelliJ IDEA 2018.3.5 and everything worked without any issue (I just had to setup the android sdk path in the local.properties file)

I also tried that “ok apply suggestion” but everything remained the same. I’ll try to reinstall IDEA, but thanks for your help!

@itspecialists Do you still have issues with this?

I feel the article is missing some information at the end.

There’s a paragraph saying " At this point, you need to call toNativeImage() on your ByteArray and return it from the success callback. Compile and that’s it!"

I was searching through the article because I thought I was missing something. But it turns out your article doesn’t show any loading of that ByteArray, so there’s no place to call toNativeImage(). I find this confusing.

Hi hlung!

The toNativeImage() method should be called in the getPokemonSprite(…) method inside the shared code. The ByteArray is returned from the network call.

Unfortunately right now I don’t have a pc with me so I can’t tell you file names or show images, but if you check the final project it should be pretty easy to figure out where the method is called.

Sorry if this seems too confusing, if you need additional help just leave a comment!

Thanks! I understand toNativeImage() has to be done in getPokemonSprite(…). But the tutorial doesn’t include any implementation of it so I felt a bit lost. I already tried to look at the full completed project in the article, but I cannot find any link to it. Can you show me where it is?

You can find the download link for the starter/final project at the top of the article. It’s the green “Materials” button :wink:

i didn’t get any gradle build error but steel i am not able to run this code in my device as well as in emulator. Help me out of this if you can

@jignesh50 Do you still have issues with this?

Hi!

I was successful in running the said application but I don’t quite understand this part:

“$SRCROOT/…/gradlew” -p “$SRCROOT/…/app” copyFramework
-Pconfiguration.build.dir=“$CONFIGURATION_BUILD_DIR”
-Pkotlin.build.type=“$KOTLIN_BUILD_TYPE”
-Pkotlin.target=“$KOTLIN_TARGET”

I’m not a master of anything so I maybe asking a stupid question here but please be patient.

this line → “$SRCROOT/…/gradlew” -p “$SRCROOT/…/app” copyFramework

If I understand it correctly, locates the gradlew and invoke the copyFramework task. What does the -p option do though?

the remaining lines sets some properties →
-Pconfiguration.build.dir=“$CONFIGURATION_BUILD_DIR”
-Pkotlin.build.type=“$KOTLIN_BUILD_TYPE”
-Pkotlin.target=“$KOTLIN_TARGET”

which if I understand it correctly is used by the copyFramework task but what I dont understand is where the values $CONFIGURATION_BUILD_DIR, $KOTLIN_BUILD_TYPE, $KOTLIN_TARGET come from?

Please can you help me here?

Thank you very much in advance.

Hello!
I am having a problem trying to compile the first hello example from the multiplattform video series.
My OS is macOS Mojave
kotlin-native-1.3.60
Java 1.8.0_141-b15

I am getting the following error: kotlin-native-macos-1.3.60/konan/nativelib/libllvmstubs.dylib: code signature in (/bin/kotlin-native-macos-1.3.60/konan/nativelib/libllvmstubs.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.

Could you please help me?

Thanks in advance

@coletz Can you please help with this when you get a chance? Thank you - much appreciated! :]

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!