• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

icerockdev/mobile-multiplatform-gradle-plugin: Gradle plugin for simplify Kotlin ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

icerockdev/mobile-multiplatform-gradle-plugin

开源软件地址(OpenSource Url):

https://github.com/icerockdev/mobile-multiplatform-gradle-plugin

开源编程语言(OpenSource Language):

Kotlin 100.0%

开源软件介绍(OpenSource 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.1")
    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.



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap