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

Francis Mariano

01/22/2021, 11:45 AM
Hello. Is anyone with problem to add 3rd party library in iOS side project? For example, I want to add Cartography or SnapKit on iOS project, so I have created the Podfile and execute 
pod install
 command, until here with no problem. However when I build the code on Xcode I get the following message:
Copy code
Link /Users/engenharia/Library/Developer/Xcode/DerivedData/iosApp-ebvxupurowfpqseswfpszjmhtudk/Build/Products/Debug-iphonesimulator/iosApp.app/iosApp
ld: framework not found SnapKit
Ok, so I thought is necessary to add also the cocoapods library in common code. I did that normally with:
Copy code
kotlin("native.cocoapods")
ios()
cocoapods {
    summary = "Test"
    homepage = "me"

    ios.deploymentTarget = "10.0"

    pod("SnapKit", "~> 5.0")
}
Ok, all the tasks were executed with success. Again in xcode after the build the code I get a new error message:
Copy code
> Task :shared:cinteropSnapKitIosX64 FAILED
Exception in thread "main" java.lang.Error: /var/folders/l8/vxy_yfbx3wz2z0q_r5068d2h0000gn/T/tmp3849060542759213327.m:1:9: fatal error: module 'SnapKit' not found
In according to the messahe the task shared:cinteropSnapKitIosX64 failed, but it is executed with success in Android Studio.
a

Artyom Degtyarev [JB]

01/22/2021, 12:00 PM
Hello, @Francis Mariano ! As far as I can see, both of the frameworks you mention are written in Swift. As Kotlin/Native does not support pure Swift modules yet, the cinterop cannot build appropriate bindings for those pods.
f

Francis Mariano

01/22/2021, 12:08 PM
Hi, @Artyom Degtyarev [JB]!!! Ok, I understood. But, I want to use those 3rd party library just on iOS side. Is it possible to use pure Swift modules in this case? The common code does not need access those library.
a

Artyom Degtyarev [JB]

01/22/2021, 1:32 PM
What do you mean by the “iOS side” here? As there is no option to generate bindings, it is not possible to use the library from Kotlin code.
k

Kris Wong

01/22/2021, 2:16 PM
if they're a dependency of the app and not the kotlin module, then why add them to the module? just add them to your app's Podfile.
f

Francis Mariano

01/22/2021, 3:50 PM
Hello @Artyom Degtyarev [JB] iOS side = iosApp (no common code is used) @Kris Wong Ok, you are right. I tried to add them to my app's Podfile. However when I try to build the code the framework is not found. PS: The framework is found and build with success in a default iOS project, but when I try the same thing in a KMM project the framework is not found and the build fails.
k

Kris Wong

01/22/2021, 4:01 PM
you are saying you added the pod as a dependency to your app's Podfile, and the module was not found in that case? what does this have to do with your KMM module?
f

Francis Mariano

01/22/2021, 4:51 PM
you are saying you added the pod as a dependency to your app's Podfile, and the module was not found in that case?
Yes, I know it is not have to do with KMM module, but when the KMM is added in an iOS project the framework is not found. Please, let me know if there are some workaround to fix that. Thank you
k

Kris Wong

01/22/2021, 4:52 PM
so your KMM module was added to your app using cocoapods, and then when building your app, that module is not found?
what does your Podfile look like?
f

Francis Mariano

01/22/2021, 5:06 PM
KMM module is added via shared.framework and run script on Build Phases
*cd* "$SRCROOT/.." ./gradlew :shared:packForXCode -PXCODE_CONFIGURATION=${CONFIGURATION}
Podfile
Copy code
# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'

target 'iosApp' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for iosApp
  pod 'Cartography', '~> 4.0'

  target 'iosAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'iosAppUITests' do
    # Pods for testing
  end

end
k

Kris Wong

01/22/2021, 5:09 PM
dunno. if your framework file is added to the project, that should be the only requirement.
f

Francis Mariano

01/22/2021, 5:16 PM
😫 Steps to reproduce my problem: 1- Create a new project in Android Studio with KMM plugin. 2- Build it. 3- Add the podfile in iosApp root folder 4- Install the podfile 5- Open the iosApp.xcworkspace 6- Build the project 7- Build fails with message: Framework Cartography Not Found I guess can be a easy configuration to fix that, but I do not know what to do. 😞
a

Artyom Degtyarev [JB]

01/22/2021, 5:33 PM
Probably, this is about iosApp Xcode project missing the
$(inherited)
option in the Framework Search Path list. There was an issue on YouTrack about it some time ago.
f

Francis Mariano

01/22/2021, 5:49 PM
Well done!! Thank you so much both of you!!! https://youtrack.jetbrains.com/issue/KT-42729
k

Kris Wong

01/22/2021, 6:02 PM
gah, woops!
i guess i never had an issue because pod install warns about it
f

Francis Mariano

01/22/2021, 6:03 PM
sorry, I am newbie with iOS universe 🙂
a

Artyom Degtyarev [JB]

01/22/2021, 6:12 PM
That’s not your fault. KMM plugin’s project wizard was not intended to add cocoapods seamlessly. It has this option specially set to look for the framework in some particular folder. Also, the Gradle is extended with a task(packForXcode) placing the framework into it. Seems like a fragile scheme, but it works nicely out-of-the-box. KMM team is working on making it better, watch https://youtrack.jetbrains.com/issue/KT-41743 for updates.
k

Kris Wong

01/22/2021, 6:15 PM
on iOS you're starting with a handicap w.r.t to distribution. the tools on that platform suck, frankly speaking
so trying to fit Kotlin modules into that picture is going to be difficult
hopefully someday it will all be Swift and we'll be able to use Swift Package Manager
f

Francis Mariano

01/22/2021, 6:30 PM
ok, thank you so much again
11 Views