ui-material to MPP
Test: ./gradlew buildOnSrever
Change-Id: I971e56a36bfbe5771e5cf0dbd0ce694aa742603b
Relnote: N/A
diff --git a/ui/ui-material/icons/core/build.gradle b/ui/ui-material/icons/core/build.gradle
index 024dae1..740f4d5 100644
--- a/ui/ui-material/icons/core/build.gradle
+++ b/ui/ui-material/icons/core/build.gradle
@@ -26,16 +26,24 @@
id("AndroidXPlugin")
id("com.android.library")
id("AndroidXUiPlugin")
- id("org.jetbrains.kotlin.android")
+ id("kotlin-multiplatform")
}
-dependencies {
- implementation(KOTLIN_STDLIB)
+kotlin {
+ android()
+ sourceSets {
+ commonMain.dependencies {
+ implementation(KOTLIN_STDLIB_COMMON)
+ api project(":compose:ui:ui")
+ }
- api project(":compose:ui:ui")
+ androidMain.dependencies {
+ implementation(KOTLIN_STDLIB)
+ }
+ }
}
-IconGenerationTask.registerCoreIconProject(project, android)
+IconGenerationTask.registerCoreIconProject(project)
androidx {
name = "AndroidX Core Material Icons"
diff --git a/ui/ui-material/icons/core/src/main/AndroidManifest.xml b/ui/ui-material/icons/core/src/androidMain/AndroidManifest.xml
similarity index 100%
rename from ui/ui-material/icons/core/src/main/AndroidManifest.xml
rename to ui/ui-material/icons/core/src/androidMain/AndroidManifest.xml
diff --git a/ui/ui-material/icons/core/src/main/java/androidx/ui/material/icons/Icons.kt b/ui/ui-material/icons/core/src/commonMain/kotlin/androidx/ui/material/icons/Icons.kt
similarity index 100%
rename from ui/ui-material/icons/core/src/main/java/androidx/ui/material/icons/Icons.kt
rename to ui/ui-material/icons/core/src/commonMain/kotlin/androidx/ui/material/icons/Icons.kt
diff --git a/ui/ui-material/icons/extended/build.gradle b/ui/ui-material/icons/extended/build.gradle
index 8f774c6..7efed7e 100644
--- a/ui/ui-material/icons/extended/build.gradle
+++ b/ui/ui-material/icons/extended/build.gradle
@@ -26,29 +26,37 @@
id("AndroidXPlugin")
id("com.android.library")
id("AndroidXUiPlugin")
- id("org.jetbrains.kotlin.android")
+ id("kotlin-multiplatform")
}
dependencies {
kotlinPlugin project(path: ":compose:compose-compiler")
- implementation(KOTLIN_STDLIB)
-
- api project(":compose:material:material-icons-core")
- implementation project(":compose:runtime:runtime")
-
- androidTestImplementation project(":compose:foundation:foundation")
- androidTestImplementation project(":compose:foundation:foundation-layout")
- androidTestImplementation project(":compose:ui:ui")
- androidTestImplementation project(":ui:ui-test")
- androidTestImplementation project(":test-screenshot")
-
- androidTestImplementation(ANDROIDX_TEST_RULES)
- androidTestImplementation(ANDROIDX_TEST_RUNNER)
- androidTestImplementation(JUNIT)
- androidTestImplementation(KOTLIN_REFLECT)
- androidTestImplementation(TRUTH)
}
+kotlin {
+ android()
+ sourceSets {
+ commonMain.dependencies {
+ implementation(KOTLIN_STDLIB_COMMON)
+ api project(":compose:material:material-icons-core")
+ implementation project(":compose:runtime:runtime")
+ }
+
+ androidTest.dependencies {
+ implementation project(":compose:foundation:foundation")
+ implementation project(":compose:foundation:foundation-layout")
+ implementation project(":compose:ui:ui")
+ implementation project(":ui:ui-test")
+ implementation project(":test-screenshot")
+
+ implementation(ANDROIDX_TEST_RULES)
+ implementation(ANDROIDX_TEST_RUNNER)
+ implementation(JUNIT)
+ implementation(KOTLIN_REFLECT)
+ implementation(TRUTH)
+ }
+ }
+}
android.buildTypes.all {
// Jacoco hangs intermittently due to the large number of files
testCoverageEnabled = false
diff --git a/ui/ui-material/icons/extended/src/androidTest/AndroidManifest.xml b/ui/ui-material/icons/extended/src/androidAndroidTest/AndroidManifest.xml
similarity index 100%
rename from ui/ui-material/icons/extended/src/androidTest/AndroidManifest.xml
rename to ui/ui-material/icons/extended/src/androidAndroidTest/AndroidManifest.xml
diff --git a/ui/ui-material/icons/extended/src/androidTest/java/androidx/ui/material/icons/test/IconComparisonTest.kt b/ui/ui-material/icons/extended/src/androidAndroidTest/kotlin/androidx/ui/material/icons/test/IconComparisonTest.kt
similarity index 100%
rename from ui/ui-material/icons/extended/src/androidTest/java/androidx/ui/material/icons/test/IconComparisonTest.kt
rename to ui/ui-material/icons/extended/src/androidAndroidTest/kotlin/androidx/ui/material/icons/test/IconComparisonTest.kt
diff --git a/ui/ui-material/icons/extended/src/androidTest/AndroidManifest.xml b/ui/ui-material/icons/extended/src/androidMain/AndroidManifest.xml
similarity index 100%
copy from ui/ui-material/icons/extended/src/androidTest/AndroidManifest.xml
copy to ui/ui-material/icons/extended/src/androidMain/AndroidManifest.xml
diff --git a/ui/ui-material/icons/extended/src/main/AndroidManifest.xml b/ui/ui-material/icons/extended/src/main/AndroidManifest.xml
deleted file mode 100644
index 88c6032..0000000
--- a/ui/ui-material/icons/extended/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright 2020 The Android Open Source Project
-
- 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.
- -->
-<manifest package="androidx.ui.material.icons" />
diff --git a/ui/ui-material/icons/generator/build.gradle b/ui/ui-material/icons/generator/build.gradle
index 286a7a6..9158245 100644
--- a/ui/ui-material/icons/generator/build.gradle
+++ b/ui/ui-material/icons/generator/build.gradle
@@ -30,6 +30,7 @@
implementation(AGP_STABLE)
implementation(GUAVA)
+ implementation(KOTLIN_GRADLE_PLUGIN)
implementation(KOTLIN_STDLIB)
implementation(KOTLINPOET)
implementation(XMLPULL)
diff --git a/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconGenerationTask.kt b/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconGenerationTask.kt
index 6fe7284..d55750b 100644
--- a/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconGenerationTask.kt
+++ b/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconGenerationTask.kt
@@ -27,6 +27,8 @@
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
+import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
+import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import java.io.File
/**
@@ -70,11 +72,11 @@
@get:OutputDirectory
val generatedSrcMainDirectory: File
- get() = buildDirectory.resolve("src/main/kotlin")
+ get() = buildDirectory.resolve("src/commonMain/kotlin")
@get:OutputDirectory
val generatedSrcAndroidTestDirectory: File
- get() = buildDirectory.resolve("src/androidTest/kotlin")
+ get() = buildDirectory.resolve("src/androidAndroidTest/kotlin")
@get:OutputDirectory
val generatedResourceDirectory: File
@@ -92,10 +94,8 @@
* [androidx.ui.material.icons.generator.CoreIcons], and no tests.
*/
@JvmStatic
- fun registerCoreIconProject(project: Project, libraryExtension: LibraryExtension) {
- libraryExtension.libraryVariants.all { variant ->
- CoreIconGenerationTask.register(project, variant)
- }
+ fun registerCoreIconProject(project: Project) {
+ CoreIconGenerationTask.register(project)
}
/**
@@ -105,9 +105,7 @@
*/
@JvmStatic
fun registerExtendedIconProject(project: Project, libraryExtension: LibraryExtension) {
- libraryExtension.libraryVariants.all { variant ->
- ExtendedIconGenerationTask.register(project, variant)
- }
+ ExtendedIconGenerationTask.register(project)
libraryExtension.testVariants.all { variant ->
IconTestingGenerationTask.register(project, variant)
@@ -123,14 +121,28 @@
* Registers a new [T] in [this], and sets [IconGenerationTask.buildDirectory] depending on
* [variant].
*
+ * @param variant the [BaseVariant] to associate this task with, or `null` if this task does not
+ * change between variants.
* @return the created [T] of [IconGenerationTask]
*/
+@Suppress("DefaultLocale")
fun <T : IconGenerationTask> Project.createGenerationTask(
taskName: String,
- variant: BaseVariant,
- taskClass: Class<T>
+ taskClass: Class<T>,
+ variant: BaseVariant? = null
): T {
- return tasks.create("$taskName${variant.name.capitalize()}", taskClass) {
- it.buildDirectory = project.buildDir.resolve("generatedIcons/${variant.name}")
+ val variantName = variant?.name ?: "allVariants"
+ return tasks.create("$taskName${variantName.capitalize()}", taskClass) {
+ it.buildDirectory = project.buildDir.resolve("generatedIcons/$variantName")
}
}
+
+fun Project.getMultiplatformSourceSet(name: String): KotlinSourceSet {
+ val sourceSet = project.multiplatformExtension!!.sourceSets.find { it.name == name }
+ return requireNotNull(sourceSet) {
+ "No source sets found matching $name"
+ }
+}
+
+private val Project.multiplatformExtension
+ get() = extensions.findByType(KotlinMultiplatformExtension::class.java)
diff --git a/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconSourceTasks.kt b/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconSourceTasks.kt
index 2601163..439a7dc 100644
--- a/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconSourceTasks.kt
+++ b/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconSourceTasks.kt
@@ -18,8 +18,8 @@
import androidx.ui.material.icons.generator.CoreIcons
import androidx.ui.material.icons.generator.IconWriter
-import com.android.build.gradle.api.BaseVariant
import org.gradle.api.Project
+import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
/**
* Task responsible for converting core icons from xml to a programmatic representation.
@@ -30,15 +30,14 @@
companion object {
/**
- * Registers [CoreIconGenerationTask] in [project] for [variant].
+ * Registers [CoreIconGenerationTask] in [project].
*/
- fun register(project: Project, variant: BaseVariant) {
+ fun register(project: Project) {
val task = project.createGenerationTask(
"generateCoreIcons",
- variant,
CoreIconGenerationTask::class.java
)
- variant.registerIconGenerationTask(project, task)
+ registerIconGenerationTask(project, task)
}
}
}
@@ -52,28 +51,25 @@
companion object {
/**
- * Registers [ExtendedIconGenerationTask] in [project] for [variant].
+ * Registers [ExtendedIconGenerationTask] in [project].
*/
- fun register(project: Project, variant: BaseVariant) {
+ fun register(project: Project) {
val task = project.createGenerationTask(
"generateExtendedIcons",
- variant,
ExtendedIconGenerationTask::class.java
)
- variant.registerIconGenerationTask(project, task)
+ registerIconGenerationTask(project, task)
}
}
}
/**
- * Helper to register [task] as the java source generating task for [project].
+ * Helper to register [task] as the Kotlin source generating task for [project].
*/
-private fun BaseVariant.registerIconGenerationTask(
+private fun registerIconGenerationTask(
project: Project,
task: IconGenerationTask
) {
- registerJavaGeneratingTask(task, task.generatedSrcMainDirectory)
- // TODO: b/144249620 - fixed in AGP 4.0.0 alpha 4 +
- javaCompileProvider.configure { it.enabled = false }
- project.tasks.named("runErrorProne").configure { it.enabled = false }
+ val sourceSet = project.getMultiplatformSourceSet(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME)
+ sourceSet.kotlin.srcDir(project.files(task.generatedSrcMainDirectory).builtBy(task))
}
diff --git a/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconTestingGenerationTask.kt b/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconTestingGenerationTask.kt
index ac01c44..3227b371 100644
--- a/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconTestingGenerationTask.kt
+++ b/ui/ui-material/icons/generator/src/main/kotlin/androidx/ui/material/icons/generator/tasks/IconTestingGenerationTask.kt
@@ -58,13 +58,15 @@
fun register(project: Project, variant: BaseVariant) {
val task = project.createGenerationTask(
"generateTestFiles",
- variant,
- IconTestingGenerationTask::class.java
+ IconTestingGenerationTask::class.java,
+ variant
)
variant.registerGeneratedResFolders(
project.files(task.generatedResourceDirectory).builtBy(task)
)
- variant.registerJavaGeneratingTask(task, task.generatedSrcAndroidTestDirectory)
+ val sourceSet = project.getMultiplatformSourceSet("androidAndroidTest")
+ sourceSet.kotlin
+ .srcDir(project.files(task.generatedSrcAndroidTestDirectory).builtBy(task))
}
}
}