Hi there, I'm trying to import cocoapods library i...
# kotlin-native
f
Hi there, I'm trying to import cocoapods library in my k/n project, but following all available instructions, leaves me with unresolved import. I'm using cocoapods gradle plugin, add pods into cocoapods{}, generate podspec, add my podspec into podfile of ios project, make pod install, run workspace, build it, go back to android studio project and i have unresolved import :/
a
Hello! Have you tried to “invaludate caches and restart”? If so, let’s check if
.klib
is actually presented an your project files. There should be something like
<projectName>-cinterop-<podName>.klib
.
f
i can see them
But still
Copy code
import cocoapods.FirebaseFirestore
marks cocoapods in red
a
Okay. What are the AS and Kotlin plugin versions here?
f
AS 3.5.3
and 1.3.61 for kotlin
the issue is not importing my k/n library as pod into xcode, but using for example FirebaseFirestore pod in iosMain in kotlin native
a
I understand. Under Kotlin plugin I meant the IDE plugin, not the gradle one. It might be outdated a bit, and therefore unable to interpret KLIB contents correctly. Please check it and post here, ok?
f
v1.3.61-release-Studio3.5-1
i think this is latest plugin version from stable channel
a
Correct. I’m trying to reproduce it locally now, as soon as I’m sure the setup is the same. Also, maybe this(https://github.com/touchlab/FirestoreKMP) library can be interesting for you.
f
seen it 🙂 this was place where i first saw, i could use cocoapods in kn, unfortunately even this project produces same result, unresolved import 😞
also without success
a
Hmm. I just followed all steps you mention, and in this case
import cocoapods.FirebaseFirestore.*
seems to resolve correctly. Have you tried to invalidate caches? For now, I’m kinda out of ideas here.
f
yes, i've tried to invalidate caches
maybe try to list all steps you did, i think this might be a one little thing that prevents it from working, one that noone is mentioning because it might to be obious
a
Ok, I am 99% sure you made everything correct, but here it goes. • I took a sample project, that you probably saw it (https://stackoverflow.com/questions/60126503/how-to-add-thirdparty-ios-pod-library-into-kotlin-native-project-getting-error/), • Added
pod("FirebaseFirestore")
line in the
SharedCode/build.gradle.kts
, cocoapods section. • Then executed
:SharedCode:podspec
, opened Xcode project and built it. • After that, in the Android Studio added import as above into the
SharedCode/src/iosMain/kotlin/actual.kt
file.
f
hmm
i'm not using .kts build files
maybe this is whats wrong
i'll try kts tommorow and let you know of result
thank you 🙂
So, checked out this project, added pod line as you, generated podspec, done pod install and tried to build
/Users/lynx/Library/Developer/Xcode/DerivedData/KotlinIOS-fdgjjjppacwrrnfxaylegnufjofy/Build/Intermediates.noindex/KotlinIOS.build/Debug-iphonesimulator/KotlinIOS.build/Script-47729E7122F480EB00B9B36B.sh: line 4: cd: /Users/lynx/Workspaces/Tests/mpp-ios-android/native/KotlinIOS/../../SharedCode/build/xcode-frameworks: No such file or directory
/Users/lynx/Library/Developer/Xcode/DerivedData/KotlinIOS-fdgjjjppacwrrnfxaylegnufjofy/Build/Intermediates.noindex/KotlinIOS.build/Debug-iphonesimulator/KotlinIOS.build/Script-47729E7122F480EB00B9B36B.sh: line 5: ./gradlew: No such file or directory
this wasn't the case before (with non .kts) build
a
Do those directory and file actually exist? I mean,
/Users/lynx/Workspaces/Tests/mpp-ios-android/native/KotlinIOS/../../SharedCode/build/xcode-frameworks
and
/Users/lynx/Workspaces/Tests/mpp-ios-android/gradlew
. If not, please try to execute
:SharedCode:packForXcode
task manually, at least it should create the
xcode-frameworks
directory.
f
ok, so after step packForXcode
> Configure project :SharedCode
Kotlin Multiplatform Projects are an experimental feature.
> Task :SharedCode:generateDefAFNetworking UP-TO-DATE
> Task :SharedCode:cinteropAFNetworkingIos FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':SharedCode:cinteropAFNetworkingIos'.
> Cannot perform cinterop processing for AFNetworking: cannot determine headers location.
 
Probably the build is executed from command line.
 
Note that a Kotlin/Native module using CocoaPods dependencies can be built only from Xcode.
this is xcode fail log
a
Have you adjusted
Framework Search Paths
in your project?
f
To be sure i done it right
under framework Search Paths i have Debug and Release
under debug i hit little + button
and just write $(inherited)
👌 1
clean, build, same result
i know, it is experimental feauture, but damn, it is hard to use
a
Okay, can you look at this patch? That’s all of my edits.
f
applying and testing...
AFNetworking resolved
🙀 1
in imports
but FirebaseFirestore not o_O
i'll try to invalidate caches and restart studio
works!
🎉 1
inherited should be in framework search paths and header search paths?
a
I think so. In my case, it was there already. You know, usually cocoaPods plugin is much less pain, especially using it from the Xcode side.
f
Yeah, i'm trying to apply necesary changes to my project and i'll let you know if i succeeded, maybe we could then send info to jetbrains to update their readme 😉
It's alive! (i mean, it's working!) 😄
thank you very much for all your help
🙂 1
it looks like, .kts is required
it won't work on normal gradle file
one last question, what should i add to .kts to have in androidMain access to Android libraries?
a
Well, have a look at this doc(https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#android-support). Basically, you’ll need to add a plugin to your script, and then use
android()
target instead of
jvm("android")
. And then, your android source sets will become Android-styled(I mean, all this
main, debugMain, etc
instead of
<targetName><Main | Test>
, so the dependencies section will need some adjustments.
f
ok, thank you