Skip to content

Instantly share code, notes, and snippets.

@Starmel
Last active July 21, 2024 12:12
Show Gist options
  • Save Starmel/95ad191dea704cc9c36ea6ff34452a8a to your computer and use it in GitHub Desktop.
Save Starmel/95ad191dea704cc9c36ea6ff34452a8a to your computer and use it in GitHub Desktop.

Simple KMM framework transitive linking

Problem:

  1. Required to share KMM library with linked Xcode Frameworks to other KMM projects
  2. Xcode project is use Cocoapods
  3. KMM project (library consumer) is built by Xcode with :embedAndSignAppleFrameworkForXcode

How to:

  1. Add KotlinDSL plugin framework.link.gradle.kts to buildSrc of both projects - library and library consumer.
  2. In build.gradle.kts of the library declare used Xcode Frameworks, example:
plugins {
    ..
}

frameworkLinking {
    framework {
        name = "AppsFlyerLib"
        defFile = "binaries/def/AppsFlyerFramework.def"
        searchPath = "binaries/AppsFlyerLib.xcframework"
    }
    framework {
        name = "FirebaseAnalytics"
        defFile = "binaries/def/FirebaseAnalytics.def"
        searchPath = "binaries/FirebaseAnalytics.xcframework"
    }
    framework {
        name = "YandexMobileMetrica"
        defFile = "binaries/def/YandexMobileMetrica.def"
        searchPath = "binaries/YandexMobileMetrica.xcframework"
    }
}

kotlin {
    ..
}
  1. To link all available frameworks of Xcode project in build.gradle.kts of the library consumer project add:
plugins {
    ..
}

frameworkLinking {
    useXcodeFrameworks()
}

kotlin {
    ..
}

KotlinDSL plugin automatically link matching KonanTarget with .framework target. Supported: IOS_ARM64, IOS_SIMULATOR_ARM64, IOS_X64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment