Trond Tunheim
Trond Tunheim

Reputation: 115

Using Appcode with Kotlin/Native and Cocoapods

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 Podfile looks like this : Podfile

My Gradle file looks like this : build.gradle.kts

My main.kt file looks like this : main.kt

Any help is appreciated.

Upvotes: 1

Views: 1327

Answers (2)

Trond Tunheim
Trond Tunheim

Reputation: 115

Thanks for the instructions Kurt. I tried to follow them , but still run into problems.

  1. Starting new project in Appcode ( test1) , build ok in Appcode. Opening same project in Xcode , builds ok.

  2. Adds the Cocoapod plugin reference and the pod to my Gradle file and also sets version= "1.0"

  3. Runs the podspec task
  4. Issues "pod setup" , and "pod init"
  5. Adds the pod enty into the Podfile : "pod 'test1', :path => '/Users/trond/Desktop/test1/test1'" . (This comes from the output of podspec)
  6. Issues "pod install"
  7. Reopens Xcode with project : "test1.xcworkspace' and tries to build. It fails with a permision error on "gradlew"
  8. Fixing permisions on "gradlew" with "chmod 777 gradlew"
  9. Tries to build with Xcode again, it fails with : "Project 'test1' not found in root project 'test1' . The task that fails is : "$REPO_ROOT/../Supporting Files/gradlew" -p "$REPO_ROOT" :test1:syncFramework -Pkotlin.native.cocoapods.target=$KOTLIN_TARGET -Pkotlin.native.cocoapods.configuration=$CONFIGURATION -Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS" -Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS" -Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS""

$REPO_ROOT = PODS_TARGET_SRCROOT =/Users/trond/Desktop/test1/Pods/../test1

Upvotes: 1

Kurt Acosta
Kurt Acosta

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

Related Questions