Giter Site home page Giter Site logo

icerockdev / mobile-multiplatform-gradle-plugin Goto Github PK

View Code? Open in Web Editor NEW
93.0 11.0 16.0 182 KB

Gradle plugin for simplify Kotlin Multiplatform mobile configurations

License: Apache License 2.0

Kotlin 100.00%
kotlin-native android ios kotlin-multiplatform gradle-plugin

mobile-multiplatform-gradle-plugin's Introduction

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 {
    google()
    gradlePluginPortal()
}

dependencies {
    implementation("dev.icerock:mobile-multiplatform:0.14.2")
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
    implementation("com.android.tools.build:gradle:7.0.4")
}

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

Also by default iosSimulatorArm64 target will be created (with connection to iosMain and iosTest if was used ios shortcut. To disable it add into gradle.properties line:

mobile.multiplatform.withoutIosSimulatorArm64=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.

mobile-multiplatform-gradle-plugin's People

Contributors

alex009 avatar anton6tak avatar nhalase avatar nrobi144 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mobile-multiplatform-gradle-plugin's Issues

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.

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

Add plugin for change android sources location

for cases when android gradle plugin correctly work with moved resources and other we should give plugin to simple enable android resources in androidMain sourceSet instead of main

plugin should be named dev.icerock.mobile.multiplatform.android-sources. now it implemented in dev.icerock.mobile.multiplatform.targets plugin

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

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.

Add plugin for change only AndroidManifest location

if we change all android directories then android gradle plugin can broke own logic of databinding/buildflavours so we should give way to setup MPP libs without big configuration but with correctly located manifest.

KMM template in android studio now create this config:

android {
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
}

we should do it in plugin dev.icerock.mobile.multiplatform.android-manifest

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

Time to deprecate plugin

Now in Kotlin official Cocoapods plugin available option linkOnly in when we add pods dependencies - https://kotlinlang.org/docs/native-cocoapods-dsl-reference.html#pod-function .
It was last key differences between our plugin and official.

Now we can do simple gradle configuration with official kotlin-multiplatform and kotlin-cocoapods plugins.

After we migrate two own projects on official plugins (to approve that we not have reasons to stay on mobile-multiplatform-gradle-plugin) - we deprecate this plugin.

Not stable iOS build for features with BuildCocoapod-task

There is often error on task cocoapodBuild___ for project included pods both in mpp-library and feature.

Like this:

FAILURE: Build failed with an exception.
117 * What went wrong:
118 Execution failed for task ':mpp-library:cocoapodBuildBindAccountIosIphoneosArm64'.
119 > A problem occurred starting process 'command 'xcodebuild''

Build can complete success after some retry attempt. Looks like the reason in :feature:cocoapodBuild and :mpp-library:cocoapodBuild starts in the same time.

Tried to fix with adding deps in mpp-library/build.grable.kts:

val bindAccountProject = subprojects.first { it.name == "bindAccount" }

tasks
    .matching { it.name.startsWith("cocoapodBuild") }
    .whenTaskAdded {
        val mppTask = this
        bindAccountProject.tasks
            .matching { it.name == name }
            .whenTaskAdded {
                println("$mppTask dependsOn $this")
                mppTask.dependsOn(this)
            }
    }

But no result

Add up-to-date support to build cocoapod task

Now build cocoapods (used for compile cocoapod and pass it into cinterop/linking later) not support up-to-date checks and run every time, but xcode compilation take some time everytime (10seconds in case when no changes after last compilation) - in projects with many of cocoapods (just like moko-widgets) this time can be large.

In this issue we should add to buildCocoapod tasks support of UP-TO-DATE checks and, if we can, support of FROM-CACHE

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.