CocoaPods Gradle 插件 DSL 参考

Kotlin CocoaPods Gradle plugin is a tool for creating Podspec files. These files are necessary to integrate your Kotlin project with the CocoaPods dependency manager.

This reference contains the complete list of blocks, functions, and properties for the Kotlin CocoaPods Gradle plugin that you can use when working with the CocoaPods integration.

Enable the plugin

To apply the CocoaPods plugin, add the following lines to the build.gradle(.kts) file:

  1. plugins {
  2. kotlin("multiplatform") version "1.9.10"
  3. kotlin("native.cocoapods") version "1.9.10"
  4. }

The plugin versions match the Kotlin release versions. The latest stable version is 1.9.10.

cocoapods block

The cocoapods block is the top-level block for the CocoaPods configuration. It contains general information on the Pod, including required information like the Pod version, summary, and homepage, as well as optional features.

You can use the following blocks, functions, and properties inside it:

NameDescription
versionThe version of the Pod. If this is not specified, a Gradle project version is used. If none of these properties are configured, you’ll get an error.
summaryA required description of the Pod built from this project.
homepageA required link to the homepage of the Pod built from this project.
authorsSpecifies authors of the Pod built from this project.
podfileConfigures the existing Podfile file.
noPodspec()Sets up the plugin not to produce a Podspec file for the cocoapods section.
nameThe name of the Pod built from this project. If not provided, the project name is used.
licenseThe license of the Pod built from this project, its type, and the text.
frameworkThe framework block configures the framework produced by the plugin.
sourceThe location of the Pod built from this project.
extraSpecAttributesConfigures other Podspec attributes like libraries or vendored_frameworks.
xcodeConfigurationToNativeBuildTypeMaps custom Xcode configuration to NativeBuildType: “Debug” to NativeBuildType.DEBUG and “Release” to NativeBuildType.RELEASE.
publishDirConfigures the output directory for Pod publishing.
podsReturns a list of Pod dependencies.
pod()Adds a CocoaPods dependency to the Pod built from this project.
specReposAdds a specification repository using url(). This is necessary when a private Pod is used as a dependency. See the CocoaPods documentation for more information.

Targets

  • ios
  • osx
  • tvos
  • watchos

For each target, use the deploymentTarget property to specify the minimum target version for the Pod library.

When applied, CocoaPods adds both debug and release frameworks as output binaries for all of the targets.

  1. kotlin {
  2. ios()
  3. cocoapods {
  4. version = "2.0"
  5. name = "MyCocoaPod"
  6. summary = "CocoaPods test library"
  7. homepage = "https://github.com/JetBrains/kotlin"
  8. extraSpecAttributes["vendored_frameworks"] = 'CustomFramework.xcframework'
  9. license = "{ :type => 'MIT', :text => 'License text'}"
  10. source = "{ :git => '[email protected]:vkormushkin/kmmpodlibrary.git', :tag => '$version' }"
  11. authors = "Kotlin Dev"
  12. specRepos {
  13. url("https://github.com/Kotlin/kotlin-cocoapods-spec.git")
  14. }
  15. pod("example")
  16. xcodeConfigurationToNativeBuildType["CUSTOM_RELEASE"] = NativeBuildType.RELEASE
  17. }
  18. }

framework block

The framework block is nested inside cocoapods and configures the framework properties of the Pod built from the project.

Note that baseName is a required field.

CocoaPods Gradle 插件 DSL 参考 - 图1

NameDescription
baseNameA required framework name. Use this property instead of the deprecated frameworkName.
isStaticDefines the framework linking type. It’s dynamic by default.
transitiveExportEnables dependency export.
  1. kotlin {
  2. cocoapods {
  3. framework {
  4. baseName = "MyFramework"
  5. isStatic = false
  6. export(project(":anotherKMMModule"))
  7. transitiveExport = true
  8. }
  9. }
  10. }

pod() function

The pod() function call adds a CocoaPods dependency to the Pod built from this project. Each dependency requires a separate function call.

You can specify the name of a Pod library in the function parameters and additional parameter values, like the version and source of the library, in its configuration block:

NameDescription
versionThe library version. To use the latest version of the library, omit the parameter.
sourceConfigures the Pod from:
  • The Git repository using git(). In the block after git(), you can specify commit to use a specific commit, tag to use a specific tag, and branch to use a specific branch from the repository
  • The local repository using path()
  • An archived (tar, jar, zip) Pod folder using url()
  • packageNameSpecifies the package name.
    extraOptsSpecifies the list of options for a Pod library. For example, specific flags: extraOpts = listOf(“-compiler-option”)
    linkOnlyInstructs the CocoaPods plugin to use Pod dependencies with dynamic frameworks without generating cinterop bindings. If used with static frameworks, the option will remove the Pod dependency entirely.
    interopBindingDependenciesContains a list of dependencies to other Pods. This list is used when building a Kotlin binding for the new Pod.
    useInteropBindingFrom()Specifies the name of the existing Pod that is used as dependency. This Pod should be declared before the function execution. The function instructs the CocoaPods plugin to use a Kotlin binding of the existing Pod when building a binding for the new one.
    1. kotlin {
    2. ios()
    3. cocoapods {
    4. summary = "CocoaPods test library"
    5. homepage = "https://github.com/JetBrains/kotlin"
    6. ios.deploymentTarget = "13.5"
    7. pod("pod_dependency") {
    8. version = "1.0"
    9. linkOnly = true
    10. source = path(project.file("../pod_dependency"))
    11. }
    12. }
    13. }