Skip to content

Commit 5455aa8

Browse files
authored
Merge pull request #51 from icerockdev/#49-#50-android-plugins
#49 #50 android plugins
2 parents f7d2e8a + 89e98a0 commit 5455aa8

11 files changed

+97
-46
lines changed

.github/workflows/create-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ jobs:
3939
with:
4040
commitish: ${{ github.ref }}
4141
tag_name: release/${{ github.event.inputs.version }}
42-
release_name: Release ${{ github.event.inputs.version }}
42+
release_name: ${{ github.event.inputs.version }}
4343
body: "Will be filled later"
4444
draft: true

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repositories {
1313
}
1414

1515
dependencies {
16-
implementation("dev.icerock:mobile-multiplatform:0.11.0")
16+
implementation("dev.icerock:mobile-multiplatform:0.12.0")
1717
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20")
1818
implementation("com.android.tools.build:gradle:4.1.1")
1919
}
@@ -31,7 +31,8 @@ plugins {
3131
```
3232

3333
Plugin automatically setup android, ios targets.
34-
For Android setup sourceSet path to `androidMain`.
34+
Android target also automatically configured with `dev.icerock.mobile.multiplatform.android-manifest`
35+
and `dev.icerock.mobile.multiplatform.android-sources` plugins.
3536

3637
By default used `ios()` targets creation with intermediate source set `iosMain`. To disable it add
3738
into `gradle.properties` line:
@@ -44,6 +45,28 @@ To disable warning about used ios targets add into `gradle.properties` line:
4445
mobile.multiplatform.iosTargetWarning=false
4546
```
4647

48+
### Setup AndroidManifest.xml in androidMain sourceSet
49+
`build.gradle.kts`
50+
```kotlin
51+
plugins {
52+
id("dev.icerock.mobile.multiplatform.android-manifest")
53+
}
54+
```
55+
56+
After enable this plugin you can move `AndroidManifest.xml` from `src/main/AndroidManifest.xml` to
57+
`src/androidMain/AndroidManifest.xml`
58+
59+
### Setup android sourceSets in android prefixed source sets
60+
`build.gradle.kts`
61+
```kotlin
62+
plugins {
63+
id("dev.icerock.mobile.multiplatform.android-sources")
64+
}
65+
```
66+
67+
After enable this plugin you can move android's `main` source set to `androidMain`, `release`
68+
to `androidRelease`, `test` to `androidTest` etc.
69+
4770
### Setup cocoapods integration for iOS
4871
`build.gradle.kts`
4972
```kotlin

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group = "dev.icerock"
14-
version = "0.11.0"
14+
version = "0.12.0"
1515

1616
repositories {
1717
mavenCentral()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.icerock.gradle
6+
7+
import com.android.build.gradle.LibraryExtension
8+
import org.gradle.api.Plugin
9+
import org.gradle.api.Project
10+
11+
class AndroidManifestPlugin : Plugin<Project> {
12+
override fun apply(target: Project) {
13+
target.plugins.withId("com.android.library") {
14+
val androidExtension = target.extensions.findByType(LibraryExtension::class.java)!!
15+
val mainSourceSet = androidExtension.sourceSets.getByName("main")
16+
val newManifestPath = "src/androidMain/AndroidManifest.xml"
17+
mainSourceSet.manifest.srcFile(newManifestPath)
18+
19+
target.logger.info("set new android manifest path $newManifestPath")
20+
}
21+
}
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.icerock.gradle
6+
7+
import com.android.build.gradle.LibraryExtension
8+
import org.gradle.api.Plugin
9+
import org.gradle.api.Project
10+
11+
class AndroidSourcesPlugin : Plugin<Project> {
12+
override fun apply(target: Project) {
13+
target.plugins.withId("com.android.library") {
14+
val androidExtension = target.extensions.findByType(LibraryExtension::class.java)!!
15+
16+
androidExtension.sourceSets.configureEach {
17+
val capitalizedName = name.capitalize()
18+
val newRoot = "src/android$capitalizedName"
19+
setRoot(newRoot)
20+
21+
target.logger.info("set new root for $name android source set - $newRoot")
22+
}
23+
}
24+
}
25+
}

src/main/kotlin/dev/icerock/gradle/CocoapodsPlugin.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class CocoapodsPlugin : Plugin<Project> {
9292
pod: CocoaPodInfo,
9393
cocoaPodsExtension: CocoapodsConfig
9494
) {
95-
project.logger.debug("configure cocoaPod $pod in $target of $project")
95+
project.logger.info("configure cocoaPod $pod in $target of $project")
9696

9797
val buildTask: CompileCocoaPod = configurePodCompilation(
9898
kotlinNativeTarget = target,
@@ -116,7 +116,7 @@ class CocoapodsPlugin : Plugin<Project> {
116116
project: Project,
117117
cocoaPodsExtension: CocoapodsConfig
118118
): CompileCocoaPod {
119-
project.logger.debug("configure compilation pod $pod in $kotlinNativeTarget of $project")
119+
project.logger.info("configure compilation pod $pod in $kotlinNativeTarget of $project")
120120

121121
val (sdk, arch) = when (kotlinNativeTarget.konanTarget) {
122122
KonanTarget.IOS_ARM64 -> "iphoneos" to "arm64"
@@ -159,7 +159,7 @@ class CocoapodsPlugin : Plugin<Project> {
159159
pod: CocoaPodInfo,
160160
project: Project
161161
) {
162-
project.logger.debug("configure cInterop for pod $pod in $target of $project")
162+
project.logger.info("configure cInterop for pod $pod in $target of $project")
163163

164164
if (pod.precompiled) {
165165
createCInteropTask(

src/main/kotlin/dev/icerock/gradle/FrameworkConfig.kt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package dev.icerock.gradle
77
import KotlinNativeExportable
88
import org.gradle.api.Project
99
import org.gradle.api.artifacts.MinimalExternalModuleDependency
10+
import org.gradle.api.artifacts.ProjectDependency
1011
import org.gradle.api.provider.Provider
1112
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
1213
import org.jetbrains.kotlin.konan.target.Architecture
@@ -24,27 +25,23 @@ open class FrameworkConfig {
2425
}
2526

2627
fun export(project: Project) {
27-
ExportDeclaration.ProjectExport(
28-
project = project
29-
).let { exports.add(it) }
28+
ExportDeclaration.ProjectExport(project).let { exports.add(it) }
3029
}
3130

3231
fun export(kotlinNativeExportable: KotlinNativeExportable) {
33-
ExportDeclaration.Exportable(
34-
kotlinNativeExportable = kotlinNativeExportable
35-
).let { exports.add(it) }
32+
ExportDeclaration.Exportable(kotlinNativeExportable).let { exports.add(it) }
3633
}
3734

3835
fun export(artifact: String) {
39-
ExportDeclaration.ArtifactStringExport(
40-
artifact = artifact
41-
).let { exports.add(it) }
36+
ExportDeclaration.ArtifactStringExport(artifact).let { exports.add(it) }
4237
}
4338

4439
fun export(provider: Provider<MinimalExternalModuleDependency>) {
45-
ExportDeclaration.VersionCatalogExport(
46-
provider = provider
47-
).let { exports.add(it) }
40+
ExportDeclaration.VersionCatalogExport(provider.get()).let { exports.add(it) }
41+
}
42+
43+
fun export(project: ProjectDependency) {
44+
ExportDeclaration.ProjectExport(project.dependencyProject).let { exports.add(it) }
4845
}
4946

5047
internal sealed class ExportDeclaration {
@@ -87,10 +84,10 @@ open class FrameworkConfig {
8784
}
8885

8986
data class VersionCatalogExport(
90-
val provider: Provider<MinimalExternalModuleDependency>
87+
val externalModuleDependency: MinimalExternalModuleDependency
9188
) : ExportDeclaration() {
9289
override fun export(project: Project, framework: Framework) {
93-
framework.export(this.provider.get())
90+
framework.export(externalModuleDependency)
9491
}
9592
}
9693

src/main/kotlin/dev/icerock/gradle/MobileTargetsPlugin.kt

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@
44

55
package dev.icerock.gradle
66

7-
import com.android.build.gradle.LibraryExtension
87
import org.gradle.api.Plugin
98
import org.gradle.api.Project
109
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
1110

1211
class MobileTargetsPlugin : Plugin<Project> {
13-
override fun apply(target: Project) {
14-
target.plugins.withId("com.android.library") {
15-
val androidLibraryExtension =
16-
target.extensions.findByType(LibraryExtension::class.java)!!
12+
private val androidManifestPlugin = AndroidManifestPlugin()
13+
private val androidSourcesPlugin = AndroidSourcesPlugin()
1714

18-
setupAndroidLibrary(androidLibraryExtension)
19-
}
15+
override fun apply(target: Project) {
16+
// backward compatibility apply
17+
androidManifestPlugin.apply(target)
18+
androidSourcesPlugin.apply(target)
2019

2120
target.plugins.withId("org.jetbrains.kotlin.multiplatform") {
2221
val kmpExtension =
@@ -26,23 +25,6 @@ class MobileTargetsPlugin : Plugin<Project> {
2625
}
2726
}
2827

29-
private fun setupAndroidLibrary(libraryExtension: LibraryExtension) {
30-
libraryExtension.sourceSets {
31-
mapOf(
32-
"main" to "src/androidMain",
33-
"release" to "src/androidMainRelease",
34-
"debug" to "src/androidMainDebug",
35-
"test" to "src/androidUnitTest",
36-
"testRelease" to "src/androidUnitTestRelease",
37-
"testDebug" to "src/androidUnitTestDebug"
38-
).forEach { (name, root) ->
39-
getByName(name).run {
40-
setRoot(root)
41-
}
42-
}
43-
}
44-
}
45-
4628
private fun setupMultiplatformTargets(
4729
kmpExtension: KotlinMultiplatformExtension,
4830
project: Project
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
implementation-class=dev.icerock.gradle.AndroidManifestPlugin
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
implementation-class=dev.icerock.gradle.AndroidSourcesPlugin

0 commit comments

Comments
 (0)