GithubHelp home page GithubHelp logo

prof18 / kmp-fatframework-cocoa Goto Github PK

View Code? Open in Web Editor NEW
27.0 3.0 2.0 252 KB

A Gradle plugin to generate and publish an iOs FatFramework or XCFramework on Kotlin Multiplatform projects.

License: Apache License 2.0

Kotlin 100.00%
kotlin-multiplatform gradle-plugin cocoapods cocoapod xcframework

kmp-fatframework-cocoa's Introduction

This plugin has been archived in favour of KMP Framework Bundler. You can find a migration guide here

KMP FatFramework Cocoa

Maven Central License

KMP FatFramework Cocoa is a Gradle plugin for Kotlin Multiplatform projects that generates a FatFramework for iOS targets, or a XCFramework for Apple targets and manages the publishing process in a CocoaPod Repository.

Installation

The library is uploaded on MavenCentral, so you can easily add the dependency on the plugins block:

plugins {
    id("com.prof18.kmp.fatframework.cocoa") version "<latest-version>"
}

Usage

The plugin adds five Gradle tasks to your project.

  • buildDebugIosFatFramework that creates a FatFramework with the Debug target.

  • buildDebugXCFramework that creates a XCFramework with the Debug target.

  • buildReleaseIosFatFramework that creates a FatFramework with the Release target.

  • buildReleaseXCFramework that creates a XCFramework with the Release target.

  • generateCocoaPodRepo that generates a CocoaPod repository ready to host the Framework.

  • publishDebugIosFatFramework that publishes the Debug version of the FatFramework in the CocoaPod repository.

  • publishDebugXCFramework that publishes the Debug version of the XCFramework in the CocoaPod repository.

    The "publishDebug" task (for both the type of frameworks) takes care of everything:

    • changing the working branch from main/master to develop;
    • building the debug framework;
    • updating the version name inside the Podspec file;
    • committing the changes;
    • and publishing to remote.

    In this way, in the iOS project, you can use the latest changes published on the develop branch:

    pod '<your-library-name>', :git => "[email protected]:<git-username>/<repo-name>.git", :branch => 'develop'

    To run this task, the output path provided in the configuration must be a git repository.

  • publishReleaseIosFatFramework that publishes the Release version of the FatFramework in the CocoaPod repository.

  • publishReleaseXCFramework that publishes the Release version of the XCFramework in the CocoaPod repository.

    The "publishRelease" task (for both the type of frameworks) takes care of everything:

    • changing the working branch from develop to main/master;
    • building the release framework;
    • updating the version name inside the Podspec file;
    • committing the changes;
    • tagging the commit;
    • and publishing to remote.

    In this way, in the iOS project, you have to specify a version:

    pod '<your-library-name>', :git => "[email protected]:<git-username>/<repo-name>.git", :tag => '<version-number>'

    To run this task, the output path provided in the configuration must be a git repository.

Configuration

You can configure the plugin with the fatFrameworkCocoaConfig block in your build.gradle[.kts].

The mandatory fields are three:

  • the name of the FatFramework
  • the output path
  • the version name
  • For XCFramework support, you need to set the useXCFramework flag. When the flag is set, only the XCFramework task can be called.
fatFrameworkCocoaConfig {
    frameworkName = "LibraryName"
    outputPath = "$rootDir/../test-dest"
    versionName = "1.0"
    useXCFramework = true
}

When using a FatFramework, only iOS targets can be packed together. With XCFramework you can pack together all the Apple families: iOS, macOS, etc.

If you want to run the generateCocoaPodRepo task to generate a CocoaPod repository, you have to provide the mandatory fields mentioned above and some other parameters in the cocoaPodRepoInfo block:

  • a summary of the library
  • the homepage of the library
  • the license of the library
  • the authors of the library
  • the url of the git repository that hosts the CocoaPod repo.
fatFrameworkCocoaConfig {
    frameworkName = "LibraryName"
    outputPath = "$rootDir/../test-dest"
    versionName = "1.0"

    cocoaPodRepoInfo {
        summary = "This is a test KMP framework"
        homepage = "https://github.com/prof18/ccoca-repo-test"
        license = "Apache"
        authors = "\"Marco Gomiero\" => \"[email protected]\""
        gitUrl = "[email protected]:prof18/ccoca-repo-test.git"
    }
}

Changelog

  • The version 0.2.1 introduce some breaking changes to better support XCFrameworks. Give a look to the 0.2.1 release notes.

Sample Project

To see the plugin in action, I've published a little sample project.

Further Readings

This plugin is born from a set of unbundled Gradle tasks that I was copying between every Kotlin Multiplatform project. I've written about these tasks in an article on my website.

For more info about CocoaPod repo, I suggest reading the following resources:

License

   Copyright 2021 Marco Gomiero

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

kmp-fatframework-cocoa's People

Contributors

prof18 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kmp-fatframework-cocoa's Issues

Supporting Swift Package Manager

Thanks for this plugin ๐Ÿ˜„ !

We have a private fork which adds support for Swift package manager. This fork uses the same logic and steps you did for Cocoapods and tunes it to SPM.

Would be happy submit a PR and work to get it merged if that's a direction you want to take.

InvalidUserDataException - after adding the plugin

Hi, after adding your plugin, I'm getting the below error:
Caused by: org.gradle.api.InvalidUserDataException: You must provide the property frameworkName

My build.gradle.kts for reference:

import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("com.android.library")
    id("org.jetbrains.dokka") version Versions.dokka
    id("maven-publish")
    id("signing")
    id("com.prof18.kmp.fatframework.cocoa") version "0.2.1"
}

group = "com.msabhi"
version = "1.0.2-RC"

kotlin {
    jvm {
        compilations.all {
            kotlinOptions.jvmTarget = "1.8"
        }
        testRuns["test"].executionTask.configure {
            useJUnit()
        }
    }
    android {
        //publishLibraryVariants("release", "debug")
        publishAllLibraryVariants()
    }
    js(BOTH) {
        browser()
        nodejs()
    }
    ios()
    watchos()
    tvos()
    macosX64()
    linuxX64()
    mingwX64()
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(Dependencies.Coroutines.common)
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(Dependencies.KotlinTest.common)
                implementation(Dependencies.KotlinTest.annotations)
            }
        }
        val jvmMain by getting {
            dependencies {
                implementation(kotlin("reflect", Versions.kotlin))
            }
        }
        val jvmTest by getting {
            dependencies {
                implementation(Dependencies.KotlinTest.jvm)
                implementation(Dependencies.KotlinTest.junit)
                implementation(Dependencies.Coroutines.test)
                implementation(Dependencies.AndroidTest.core)
                implementation(Dependencies.AndroidTest.junit)
                implementation(Dependencies.AndroidTest.runner)
                implementation(Dependencies.AndroidTest.rules)
            }
        }
        val androidMain by getting {
            dependencies {
                implementation(kotlin("reflect", Versions.kotlin))
                implementation(Dependencies.Coroutines.android)
                implementation(Dependencies.Android.lifecycleRuntime)
                implementation(Dependencies.Android.lifecycleViewModel)
            }
        }
        val androidTest by getting {
            dependsOn(jvmTest)
        }
        val jsMain by getting
        val jsTest by getting {
            dependencies {
                implementation(kotlin("test-js", Versions.kotlin))
            }
        }
        val nativeMain by creating {
            dependsOn(commonMain)
        }
        val nativeTest by creating {
            dependsOn(commonTest)
        }
        val appleMain by creating {
            dependsOn(commonMain)
        }
        val appleTest by creating {
            dependsOn(commonTest)
        }
        val iosMain by getting {
            dependsOn(appleMain)
        }
        val iosTest by getting {
            dependsOn(appleTest)
        }
        val watchosMain by getting {
            dependsOn(appleMain)
        }
        val watchosTest by getting {
            dependsOn(appleTest)
        }
        val tvosMain by getting {
            dependsOn(appleMain)
        }
        val tvosTest by getting {
            dependsOn(appleTest)
        }
        val macosX64Main by getting {
            dependsOn(appleMain)
        }
        val macosX64Test by getting {
            dependsOn(appleTest)
        }
        val linuxX64Main by getting {
            dependsOn(nativeMain)
        }
        val linuxX64Test by getting {
            dependsOn(nativeTest)
        }
        val mingwX64Main by getting {
            dependsOn(nativeMain)
        }
        val mingwX64Test by getting {
            dependsOn(nativeTest)
        }
        cocoapods {
            // Configure fields required by CocoaPods.
            summary = "DryRunKotlinMPP Kotlin/Native module CocoaPods"
            homepage = "https://github.com/abhimuktheeswarar/DryRunKotlinMPP"
        }
    }
}

android {
    compileSdkVersion(Versions.Android.compileSdk)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(Versions.Android.minSdk)
        targetSdkVersion(Versions.Android.targetSdk)
    }
    //Sample
    dependencies {
        debugImplementation(kotlin("reflect", Versions.kotlin))
    }
}

val packForXcode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
    val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
    val framework =
        kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}

tasks.getByName("build").dependsOn(packForXcode)

//----------------------------------------------------------------------------------

val dokkaOutputDir = "$buildDir/docs"

tasks.dokkaHtml.configure {
    outputDirectory.set(file(dokkaOutputDir))
}

val deleteDokkaOutputDir by tasks.register<Delete>("deleteDokkaOutputDirectory") {
    delete(dokkaOutputDir)
}

val javadocJar = tasks.register<Jar>("javadocJar") {
    dependsOn(deleteDokkaOutputDir, tasks.dokkaHtml)
    archiveClassifier.set("javadoc")
    from(dokkaOutputDir)
}

publishing {
    
}

signing {
   
}

Another suggestion:
Though its good to have a develop branch for debug. It would be great, if you can make that optional.
My understanding is that, gradle cocoapods plugin generates the framework in build directory & the podspec in shared module's folder. So, if we could have a task, that copies / run the gradle cocoapods task, move / copy the generated .framework to a folder & copy / move the podspec file, optionally commit the git & push it to cocoapods trunk (for public use).

Plugin is building framework only for arm64 and X64

Hello,

I am trying to provide Cocoapod repository for our iOS team. I expected that the plugin will built the pod for all the architectures (x64, armv7, armv7s and arm64).

However, when we check the supported architectures via this command: lipo -info [nameOfFramework] it shows this message:

Architectures in the fat file: [nameOfFramework] are: x86_64 arm64

Did I miss some way how to config the plugin? My goal is to be able to deliver framework which run on all iPhone devices and simulator.

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.