CocoaPods integration

    • Such a dependency can be included in a Podfile of an Xcode project and automatically built (and rebuilt) along with this project. As a result, importing to Xcode is simplified since there is no need to write corresponding Gradle tasks and Xcode build steps manually.

    For an example of CocoaPods integration, refer to the sample.

    The CocoaPods support is implemented in a separate Gradle plugin: org.jetbrains.kotlin.native.cocoapods.

    When applied, the CocoaPods plugin does the following:

    1. Adds both debug and release frameworks as output binaries for all iOS and macOS targets.
    2. Creates a podspec task which generates a podspec file for the given project.

    The podspec generated includes a path to an output framework and script phases which automate building this framework during a build process of an Xcode project. Some fields of the podspec file can be configured using the kotlin.cocoapods { ... } code block.

    • version
    • homepage

    A version of the Gradle project is used as a value for the version field. Fieldssummary and homepage can be configured using the cocoapods code block.

    This podspec file can be referenced from a of an Xcode project. After that the framework built from the Kotlin/Native module can be used from this Xcode project. If necessary, this framework is automatically rebuilt during Xcode build process.

    To import a Kotlin/Native module in an existing Xcode project:

    1. Configure a Gradle project: apply the org.jetbrains.kotlin.native.cocoapods plugin, add and configure the targets, and specify the required podspec fields.

    2. Run the podspec task. The podspec file described above will be generated.

    3. Run pod install for the Xcode project.

    After completing these steps, you can open the generated workspace (see CocoaPods documentation) and run an Xcode build.

    The CocoaPods plugin also allows using CocoaPods libraries without manual configuring cinterop parameters (see the of the multiplatform plugin documentation). The cocoapods { ... } code block allows you to add dependencies on CocoaPods libraries.

    To use these dependencies from a Kotlin code, import a package cocoapods.<library-name>. In the example above, it’s cocoapods.AFNetworking.

    The dependencies declared in this way are added in the podspec file and downloaded during the execution of pod install.

    Search paths for libraries added in the Kotlin/Native module in this way are obtained from properties of the Xcode projects configured by CocoaPods. Thus if the module uses CocoaPods libraries, it can be build only from Xcode.

    • If a Kotlin/Native module uses a CocoaPods library, you can build this module only from an Xcode project. Otherwise the CocoaPods library cannot be resolved by the Kotlin/Native infrastructure.