Skip to content

update: old instructions on CocoaPods #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 12 additions & 34 deletions topics/development/multiplatform-cocoapods-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,63 +100,41 @@ If you encounter problems during the installation, check the [Possible issues an

## Create a project

When your environment is set up, you can create a new Kotlin Multiplatform project. For that, use the
Kotlin Multiplatform web wizard or the Kotlin Multiplatform plugin for Android Studio.
When your CocoaPods environment is set up, you can configure your Kotlin Multiplatform project to work with Pods.
The following steps show the configuration on a freshly generated project:

### Using web wizard
1. Generate a new project for Android and iOS using the [Kotlin Multiplatform IDE plugin](https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform)
(on macOS) or the [Kotlin Multiplatform web wizard](https://kmp.jetbrains.com).
If using the web wizard, unpack the archive and import the project in your IDE.
2. In the `gradle/libs.versions.toml` file, add the Kotlin CocoaPods Gradle plugin to
the `[plugins]` block:

To create a project using the web wizard and configure the CocoaPods integration:

1. Open the [Kotlin Multiplatform wizard](https://kmp.jetbrains.com) and select target platforms for your project.
2. Click the **Download** button and unpack the downloaded archive.
3. In Android Studio, select **File | Open** in the menu.
4. Navigate to the unpacked project folder and then click **Open**.
5. Add the Kotlin CocoaPods Gradle plugin to the version catalog. In the `gradle/libs.versions.toml` file,
add the following declaration to the `[plugins]` block:

```text
kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
```
6. Navigate to the root `build.gradle.kts` file of your project and add the following alias to the `plugins {}` block:

3. Navigate to the root `build.gradle.kts` file of your project and add the following alias to the `plugins {}` block:

```kotlin
alias(libs.plugins.kotlinCocoapods) apply false
```

7. Open the module where you want to integrate CocoaPods, for example the `composeApp` module, and add the following alias
to the `plugins {}` block:
4. Open the module where you want to integrate CocoaPods, for example the `composeApp` module, and add the following alias
to the `plugins {}` block of the `build.gradle.kts` file:

```kotlin
alias(libs.plugins.kotlinCocoapods)
```

Now you are ready to [configure CocoaPods in your Kotlin Multiplatform project](#configure-the-project).

### In Android Studio

To create a project in Android Studio with the CocoaPods integration:

1. Install the [Kotlin Multiplatform plugin](https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform) to Android Studio.
2. In Android Studio, select **File** | **New** | **New Project** in the menu.
3. In the list of project templates, select **Kotlin Multiplatform App** and then click **Next**.
4. Name your application and click **Next**.
5. Choose **CocoaPods Dependency Manager** as the iOS framework distribution option.

![Android Studio wizard with the Kotlin Multiplatform plugin](as-project-wizard.png){width=700}

6. Keep all other options default. Click **Finish**.

The plugin will automatically generate the project with the CocoaPods integration set up.

## Configure the project

To configure the Kotlin CocoaPods Gradle plugin in your multiplatform project:

1. In the shared module's `build.gradle(.kts)` of your project, apply the CocoaPods plugin as well as the Kotlin Multiplatform plugin.

> Skip this step if you've created your project with the [web wizard](#using-web-wizard) or
> the [Kotlin Multiplatform plugin for Android Studio](#in-android-studio).
> Skip this step if you've created your project [with the IDE plugin or the web wizard](#create-a-project).
>
{style="note"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ project. The script is integrated into the build phase of your project's build s
This integration method can work for you if you do **not** import CocoaPods dependencies in your Kotlin Multiplatform
project.

If you create a project in Android Studio, choose the **Regular framework** option to have this setup generated
automatically. If you use the [Kotlin Multiplatform web wizard](https://kmp.jetbrains.com/), direct integration
is applied by default.
If you use the [Kotlin Multiplatform IDE plugin]https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform),
direct integration is applied by default.

For more information, see [Direct integration](multiplatform-direct-integration.md).

Expand Down
32 changes: 7 additions & 25 deletions topics/development/multiplatform-project-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,14 @@ Answering these questions will help you pick the best configuration for your pro

To use a Kotlin Multiplatform shared module from an iOS app, you first need to generate
an [iOS framework](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WhatAreFrameworks.html)
from this shared module. Then, you should add it as a dependency to the iOS project:
from this shared module. Then, you should add it as a dependency to the iOS project.

![Kotlin Multiplatform shared module](kmp-shared-module.svg){width=700}
Generally, there are two options with different implementations:

It's possible to consume this framework as a local or remote dependency.
* Local dependency. Kotlin build is directly interacting with an iOS build.
* Remote dependency. Kotlin build produces an iOS framework which you then connect to an iOS project using a package manager.

You can add a dependency on a Kotlin Multiplatform module framework to the iOS project in one of the following ways:

* **Direct integration**. You connect the framework directly by adding a new run script phase to the build of the iOS
app. See [Connect the framework to your iOS project](multiplatform-integrate-in-existing-app.md#configure-the-ios-project-to-use-a-kmp-framework)
to learn how to do that in Xcode.

When you create a project with the Android Studio wizard, choose the **Regular framework** option to have this setup generated
automatically.

* **CocoaPods integration**. You connect a framework through [CocoaPods](https://cocoapods.org/), a popular dependency
manager for Swift and Objective-C projects. It can be either a local or remote dependency. For more information,
see [Use a Kotlin Gradle project as a CocoaPods dependency](multiplatform-cocoapods-xcode.md).

To set up a workflow with a local CocoaPods dependency, you can either generate the project with a wizard, or edit the
scripts manually.

* **Using SPM**. You connect a framework using the Swift package manager (SPM), an Apple tool for managing the
distribution of Swift code. We're [working on official support for SPM](https://youtrack.jetbrains.com/issue/KT-53877).
Currently, you can set up a dependency on a Swift package using XCFrameworks. For more information,
see [Swift package export setup](multiplatform-spm-export.md).
To review all available options for iOS integration, see [](multiplatform-ios-integration-overview.md).

## Module configurations

Expand Down Expand Up @@ -304,7 +286,7 @@ Xcode installed to open and run both apps after making changes to the common cod

### Remote: artifact distribution

Remote distribution means that the framework artifact is published as a CocoaPod or Swift package using SPM and consumed
Remote distribution means that the framework artifact is published using Swift Package Manager or as a CocoaPod and consumed
by the iOS app. The Android app may consume the binary dependency either locally or remotely.

Remote distribution is often used to gradually introduce the technology to existing projects. It doesn't significantly
Expand Down Expand Up @@ -346,7 +328,7 @@ That allows making changes to common Kotlin code, immediately observing the beha
code. When the functionality is ready, they can switch back to the remote dependency and publish their changes
accordingly. First, they publish changes to the shared modules, and only after that do they make changes to the apps.

For remote distribution workflows, use either CocoaPods integration or SPM. For local distribution workflow, integrate
For remote distribution workflows, use Swift Package Manager. For local distribution workflow, integrate
the framework directly.

<!-- This tutorial [TODO] describes how to switch workflows by choosing the corresponding scheme in Xcode:
Expand Down