Gradle plugin for simplify Kotlin Multiplatform mobile configurations

Overview

mobile-multiplatform
GitHub license Download

Mobile Multiplatform gradle plugin

This is a Gradle plugin for simple setup of Kotlin Multiplatform mobile Gradle modules.

Setup

buildSrc/build.gradle.kts

repositories {
    mavenCentral()
    google()
}

dependencies {
    implementation("dev.icerock:mobile-multiplatform:0.12.0")
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20")
    implementation("com.android.tools.build:gradle:4.1.1")
}

Usage

Setup mobile targets without config

build.gradle.kts

plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.multiplatform")
    id("dev.icerock.mobile.multiplatform.targets")
}

Plugin automatically setup android, ios targets. Android target also automatically configured with dev.icerock.mobile.multiplatform.android-manifest and dev.icerock.mobile.multiplatform.android-sources plugins.

By default used ios() targets creation with intermediate source set iosMain. To disable it add into gradle.properties line:

mobile.multiplatform.useIosShortcut=false

To disable warning about used ios targets add into gradle.properties line:

mobile.multiplatform.iosTargetWarning=false

Setup AndroidManifest.xml in androidMain sourceSet

build.gradle.kts

plugins {
    id("dev.icerock.mobile.multiplatform.android-manifest")
}

After enable this plugin you can move AndroidManifest.xml from src/main/AndroidManifest.xml to src/androidMain/AndroidManifest.xml

Setup android sourceSets in android prefixed source sets

build.gradle.kts

plugins {
    id("dev.icerock.mobile.multiplatform.android-sources")
}

After enable this plugin you can move android's main source set to androidMain, release to androidRelease, test to androidTest etc.

Setup cocoapods integration for iOS

build.gradle.kts

plugins {
    id("dev.icerock.mobile.multiplatform.ios-framework")
}

Plugin will setup sync gradle tasks in group cocoapods for cocoapods integration.

Example of podspec for integration here - https://github.com/icerockdev/moko-template/blob/master/mpp-library/MultiPlatformLibrary.podspec

Add artifacts to export

// optional for export dependencies into framework header
framework {
    export(project = project(":myproject"))
    export(kotlinNativeExportable = MultiPlatfomLibrary(<...>))
    export(kotlinNativeExportable = MultiPlatfomModule(<...>))
    export(arm64Dependency = "my.group:name-iosarm64:0.1.0", x64Dependency = "my.group:name-iosx64:0.1.0")
    export(artifact = "my.group:name:0.1.0") // common artifact
    export(provider = libs.myLib) // gradle 7 version catalog libraries accessors
}

Setup cocoapods integration for all Apple frameworks

build.gradle.kts

plugins {
    id("dev.icerock.mobile.multiplatform.apple-framework")
}

with framework configuration you can add dependencies to export (just like in iOS framework).

Setup CocoaPods interop

build.gradle.kts

plugins {
    id("dev.icerock.mobile.multiplatform.cocoapods")
}

cocoaPods {
    podsProject = file("../ios-app/Pods/Pods.xcodeproj") // here should be path to your Pods project
    buildConfiguration = "dev-debug" // optional, default is "debug"

    pod("MBProgressHUD") // create cInterop and link with CocoaPod where schema and module is same
    pod(schema = "moko-widgets-flat", module = "mokoWidgetsFlat") // create cInterop and link with CocoaPod where schema and module is different
    pod(schema = "moko-widgets-flat", module = "mokoWidgetsFlat", onlyLink = true) // not create cInterop - just link framework with this CocoaPod
}

Also path to Pods project and configuration can be set globally into gradle.properties

mobile.multiplatform.podsProject=ios-app/Pods/Pods.xcodeproj
mobile.multiplatform.podsConfiguration=dev-debug

podsProject should be relative path from root gradle project.

Multiple plugins in one line (deprecated, saved for backward compatibility)

plugins { 
    id("dev.icerock.mobile.multiplatform")
}

This line will enable:

  • dev.icerock.mobile.multiplatform.cocoapods
  • dev.icerock.mobile.multiplatform.targets
  • publish of android build variants - release and debug

Definition of dependencies (deprecated, saved for backward compatibility)

val mokoTime = MultiPlatformLibrary(
    android = "dev.icerock.moko:time-android:0.1.0",
    common = "dev.icerock.moko:time:0.1.0",
    iosX64 = "dev.icerock.moko:time-iosx64:0.1.0",
    iosArm64 = "dev.icerock.moko:time-iosarm64:0.1.0"
)

val appCompat = AndroidLibrary(
    name = "androidx.appcompat:appcompat:1.1.0"
)

val myFeature = MultiPlatformModule(
    name = ":mpp-library:feature:myFeature"
)

Setup dependencies (deprecated, saved for backward compatibility)

build.gradle.kts

dependencies {
    mppLibrary(mokoTime)
    androidLibrary(appCompat)
    mppModule(myFeature)
}

License

Copyright 2019 IceRock MAG Inc.

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.
Issues
  • Update ios target configuration with shortcut

    Update ios target configuration with shortcut

    The ios shortcut creates targets for iosArm64 and iosX64 while also creating an intermediate source set of iosMain. Manually configuring iosArm64 and iosX64 is no longer required as of 1.3.60.

    Signed-off-by: Nicholas J Halase [email protected]

    waiting-kotlin-update 
    opened by nhalase 3
  • Custom framework name

    Custom framework name

    Sometimes it may be needed to use some multiplatform libraries in iOS Application, and, as I understand, Swift doesn't allow us to import some frameworks with the same name. It will be useful to add an optional parameter with the default value to setupFramework method.

    enhancement 
    opened by mksmdvdff 2
  • Add ability link ios framework to kotlin mpp ios target

    Add ability link ios framework to kotlin mpp ios target

    In https://github.com/icerockdev/moko-maps used cinterop to connect with GoogleMaps cocoapod, and https://github.com/icerockdev/moko-widgets require cinterop with some iOS frameworks (wich can be implemented on project-side, not library).

    Need implement simple configurable solution of CInterop configuration.

    enhancement 
    opened by Alex009 1
  • Create readme

    Create readme

    • logo (?)
    • description with goals
    • screenshot (?)
    • features - configure mobile shared library in one line, simplified dependency management, special types for kotlin buildSrc controlled dependencies
    • simple usage (just setup shared module & add dependencies)
    • installation steps
    • detailed usage (more different types of dependencies, buildSrc dependencies definitions)
    • how to contribute
    • license block
    documentation 
    opened by Alex009 0
  • Release 0.9.1

    Release 0.9.1

    Changes

    • mavenCentral publication
    opened by Alex009 0
  • #30 maven central

    #30 maven central

    opened by Alex009 0
  • Release 0.12.0

    Release 0.12.0

    Changes

    • #49 add android-manifest plugin
    • #50 add android-sources plugin
    • fix error of targets plugin configuration
    • add project accessor support
    opened by Alex009 0
  • Publish to mavenCentral

    Publish to mavenCentral

    enhancement 
    opened by Alex009 0
  • Fix warnings from kotlin multiplatform plugin

    Fix warnings from kotlin multiplatform plugin

    we got many warning at gradle configuration:

    Kotlin Multiplatform Projects are an Alpha feature. See: https://kotlinlang.org/docs/reference/evolution/components-stability.html. To hide this message, add 'kotlin.mpp.stability.nowarn=true' to the Gradle properties.
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
    

    will be good if we fix all it in our plugin

    see https://discuss.kotlinlang.org/t/disabling-androidandroidtestrelease-source-set-in-gradle-kotlin-dsl-script/21448

    enhancement 
    opened by Alex009 0
  • publish plugin to gradlePluginPortal

    publish plugin to gradlePluginPortal

    enhancement 
    opened by Alex009 0
  • Rename output framework not worked

    Rename output framework not worked

    framework {
        name = "MyMultiCore"
    }
    

    output: MultiPlatformLibrary.framework

    bug 
    opened by DeltAagent00 0
  • Transitive onlyLink support

    Transitive onlyLink support

    If we add onlyLink = true cocoapod, but nowhere not add cinterop variant of cocoapod - we will not link with this cocoapod. and because of it in moko-crash-reporting we can't use pod("GoogleUtilities", onlyLink = true)

    but for now we can use:

    cocoaPods {
        pod("GoogleUtilities", onlyLink = true)
    }
    
    kotlin.targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java).all {
        binaries.withType(org.jetbrains.kotlin.gradle.plugin.mpp.Framework::class.java).all {
            linkerOpts("-framework", "GoogleUtilities")
        }
    }
    

    need to add linker opts in onlyLink case.

    enhancement 
    opened by Alex009 0
  • Add support of build-cache for cocoapods build tasks

    Add support of build-cache for cocoapods build tasks

    https://docs.gradle.org/current/userguide/build_cache.html#sec:task_output_caching_details

    now build cocoapods tasks may take significant build-time and on CI up-to-date mark can't be used. but build-cache can be used on CI and cocoapods artifacts is good for cache

    enhancement 
    opened by Alex009 0
  • add support of CocoaPods without module definition

    add support of CocoaPods without module definition

    some cocoapods doesn’t have module definition and to cinterop with them we can't use module = ***, we should pass header files for example - https://github.com/cloudpayments/SDK-iOS

    enhancement 
    opened by Alex009 0
  • Add generation of dummy framework to simplify pod install with cinterop

    Add generation of dummy framework to simplify pod install with cinterop

    How cocoapods detect static/dynamic framework for correct integration - https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/xcode/linkage_analyzer.rb How this implemented in kotlin plugin - https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt#L209

    now dummy generation task support dynamic frameworks too, so we can just use kotlin plugin's version

    enhancement 
    opened by Alex009 2
Releases(release/0.12.0)
Owner
IceRock Development
Kotlin Multiplatform developers team
IceRock Development
BuildConfig for Kotlin Multiplatform Project

BuildKonfig BuildConfig for Kotlin Multiplatform Project. It currently supports embedding values from gradle file. Table Of Contents Motivation Usage

Yasuhiro SHIMIZU 187 Jul 28, 2021
Kotlin Multiplatform Mobile App Template

KMMT : Kotlin Multiplatform Mobile Template Kotlin Multiplatform Mobile Development Simplified KMMT is a KMM based project template designed to simpli

Jitty Andiyan 117 Jul 19, 2021
Dependency Injection library for Kotlin Multiplatform, support iOS and Android

Multiplatform-DI library for Kotlin Multiplatform Lightweight dependency injection framework for Kotlin Multiplatform application Dependency injection

Anna Zharkova 12 Jul 27, 2021
Kotlin multiplatform benchmarking toolkit

NOTE: Starting from version 0.3.0 of the library: The library runtime is published to Maven Central and no longer published to Bintray. The Gradle plu

Kotlin 167 Jul 28, 2021
KaMP Kit by Touchlab is a collection of code and tools designed to get your mobile team started quickly with Kotlin Multiplatform.

KaMP Kit Welcome to the KaMP Kit! About Goal The goal of the KaMP Kit is to facilitate your evaluation of Kotlin Multiplatform (aka KMP). It is a coll

Touchlab 1.2k Aug 2, 2021
DI can be simple. Forget about modules and components. Just use it!

PopKorn - Kotlin Multiplatform DI PopKorn is a simple, powerful and lightweight Kotlin Multiplatform Dependency Injector. It doesn't need any modules

Pau Corbella 109 May 22, 2021
💫 A Gradle Plugin to generate your networking code from Swagger

Swagger Gradle Codegen A Gradle plugin to generate networking code from a Swagger spec file. This plugin wraps swagger-codegen, and exposes a configur

Yelp.com 356 Jul 21, 2021
Generic AST parsing library for kotlin multiplatform

kotlinx.ast kotlinx.ast is a generic AST (Abstract Syntax Tree) parsing library, Kotlin is currently the only supported language. The library is desig

null 140 Jul 27, 2021
Kotlin Multiplatform project that gets network data from Food2Fork.ca

Food2Fork Recipe App This is the codebase for a Kotlin Multiplatform Mobile course. [Watch the course](https://codingwithmitch.com/courses/kotlin-mult

Mitch Tabian 181 Jul 24, 2021
The most essential libraries for Kotlin Multiplatform development

Essenty The most essential libraries for Kotlin Multiplatform development. Supported targets: android jvm js (IR and LEGACY) iosArm64, iosX64 watchosA

Arkadii Ivanov 13 Aug 2, 2021
A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android

Blue-Falcon A Bluetooth "Cross Platform" Kotlin Multiplatform library for iOS, Android, MacOS, Raspberry Pi and Javascript. Bluetooth in general has t

Andrew Reed 146 Jul 24, 2021
Kotlin Native Xcode Plugin

Kotlin Native Xcode Support Plugin to facilitate debugging iOS applications using Kotlin Native in Xcode. Defines Kotlin files as source code, with ba

Touchlab 521 Jul 26, 2021
Koi, a lightweight kotlin library for Android Development.

Koi - A lightweight Kotlin library for Android Koi include many useful extensions and functions, they can help reducing the boilerplate code in Androi

Hello World 507 Jul 11, 2021
A collection of hand-crafted extensions for your Kotlin projects.

Splitties Splitties is a collection of small Kotlin multiplatform libraries (with Android as first target). These libraries are intended to reduce the

Louis CAD 1.8k Aug 4, 2021