u_pendra
u_pendra

Reputation: 948

Run Java dependent Kotlin for iOS

I was having a Java code for android application. I want to use same code for iOS also, after reading the flexibility about Kotlin multiplatform, thought to give a try with new cross platform solution. I converted the Java code to Kotlin, and copied in shared component in the KMP project. it ran perfectly for Android. But ran with multiple error of iOS, As the shared code have JAVA util,time,net and security packages dependency. So this code didn’t work for iOS. My question is can we run Java packages dependent kotlin code for iOS?

Upvotes: 0

Views: 319

Answers (1)

Róbert Nagy
Róbert Nagy

Reputation: 7612

Nope, your shared module can't contain jvm dependencies if you target iOS also.

For any JVM dependency you can created expected implementations with an actual jvm & native implementation for the platforms (on the JVM side you can use the Java packages that way and for the native part the iOS ones)

But for lot of the common Java dependencies already exists this abstraction in some library. See KMP libraries here

Also here's an example of how you can create the expect/actual abstractions, where the actual File on jvm can be the java.io.File

Upvotes: 4

Related Questions