Reputation: 115
I'm starting to use Kotlin/native and Appcode for iOS development. I'm trying to get Cocoapods to work with Kotlin/native, but I'm having some challenges.
I've started with the empty Kotlin/native application in AppCode and built that, it builds fine and runs in the Emulator.
Then I try to add Cocoapods with "AFNetworking" I run into trouble. I have tried to follow the JetBrains Kotlin/native sample : https://github.com/JetBrains/kotlin-native/tree/master/samples/cocoapods , but still no luck.
The problems that I'm facing is :
I might have overlooked some configurations, but I cant't figure it out.
I'm using Appcode 2019.3.1 , Xcode 11.3(11C29) and Cocoapods 1.8.4
My Gradle file looks like this :
My main.kt file looks like this :
Any help is appreciated.
Upvotes: 1
Views: 1327
Reputation: 115
Thanks for the instructions Kurt. I tried to follow them , but still run into problems.
Starting new project in Appcode ( test1) , build ok in Appcode. Opening same project in Xcode , builds ok.
Adds the Cocoapod plugin reference and the pod to my Gradle file and also sets version= "1.0"
$REPO_ROOT = PODS_TARGET_SRCROOT =/Users/trond/Desktop/test1/Pods/../test1
Upvotes: 1
Reputation: 2537
You have to build the project from Xcode first.
Generate the podspec using the podspec
gradle task and modify that accordingly then add that to your Podfile
target 'project' do
...
pod 'YourFrameworkName', :path => 'path/to/your-kotlin-library'
end
You could check it here: https://kotlinlang.org/docs/reference/native/cocoapods.html#interoperability
Edit:
Also, here's a sample of a Kotlin/Native using AFNetworking
in the Kotlin code. https://github.com/JetBrains/kotlin-native/tree/master/samples/cocoapods
Edit 2:
Again, you have to link the K/N project to your Xcode Project and build it there.
Step 1: Add the pod to your Gradle file
kotlin {
cocoapods {
...
pod("AFNetworking")
}
}
Step 2: Generate the podspec file through ./gradlew shared-module:podspec
This will generate the podspec file which you might have to modify before building.
Step 3: Use this in your Podfile
target 'project' do
...
pod 'YourFrameworkName', :path => 'path/to/your-kotlin-library'
end
Step 4: pod install
Step 5: Build it in Xcode
After that, you'll be able to reference it in K/N by importing cocoapods.AFNetworking.*
Upvotes: 2