From 81cd776ef123f42a69942f2b846b4b37d43f10f0 Mon Sep 17 00:00:00 2001 From: nian1 Date: Tue, 9 Jul 2024 18:57:30 +0800 Subject: [PATCH 1/4] Update android.yml --- .github/workflows/android.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index abc1ec3..7ddd45c 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -26,10 +26,10 @@ jobs: runs-on: self-hosted steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'corretto' From 2a0d0adf5222f417a69130f2c5c8a1ea1c736f02 Mon Sep 17 00:00:00 2001 From: nian1 Date: Tue, 9 Jul 2024 18:57:40 +0800 Subject: [PATCH 2/4] Update ios.yml --- .github/workflows/ios.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index e9a1ad8..22b3b5c 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -26,10 +26,10 @@ jobs: runs-on: self-hosted steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'corretto' @@ -37,8 +37,8 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - - uses: actions/checkout@v2 - - uses: actions/cache@v2 + - uses: actions/checkout@v4 + - uses: actions/cache@v4 with: path: iosApp/Pods key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }} From f5460c8c0a11b791ffb742f7fa3a25dd22b1fe31 Mon Sep 17 00:00:00 2001 From: nian1 Date: Tue, 9 Jul 2024 19:24:30 +0800 Subject: [PATCH 3/4] Optimizing compose compiler config --- androidApp/build.gradle.kts | 9 +--- build-logic/convention/build.gradle.kts | 16 +++++-- ...droidApplicationComposeConventionPlugin.kt | 36 +++++++++++++++ .../AndroidLibraryComposeConventionPlugin.kt | 36 +++++++++++++++ .../src/main/kotlin/BuildSupportPlugin.kt | 9 ---- .../convention/src/main/kotlin/ProjectExt.kt | 46 +++++++++++++++++++ gradle/libs.versions.toml | 10 +++- shared/build.gradle.kts | 2 +- 8 files changed, 142 insertions(+), 22 deletions(-) create mode 100644 build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt create mode 100644 build-logic/convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt create mode 100644 build-logic/convention/src/main/kotlin/ProjectExt.kt diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index b0924de..cbe44f9 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -1,9 +1,9 @@ import java.util.Properties plugins { - alias(libs.plugins.android.application) - kotlin("android") + alias(libs.plugins.android.application.compose) alias(libs.plugins.compose.compiler) + kotlin("android") } android { @@ -65,11 +65,6 @@ android { } } -composeCompiler { - enableStrongSkippingMode = true - reportsDestination = layout.buildDirectory.dir("compose_compiler") -} - dependencies { implementation(projects.shared) // implementation(projects.sharedCompose) diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 05aae7a..7ddf5ea 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -29,20 +29,30 @@ dependencies { compileOnly(libs.gradlePlugin.kotlin) { exclude(group = "org.ow2.asm") } - implementation(libs.bundles.asm) + compileOnly(libs.bundles.asm) implementation(libs.gradlePlugin.spotless) + implementation(libs.gradlePlugin.compose.compiler) } gradlePlugin { plugins { val prefix = "com.jithub.gradle" - register("build-logic") { + register("buildLogic") { id = "$prefix.build-logic" implementationClass = "BuildLogic" } - register("build-support") { + register("buildSupport") { id = "$prefix.build-support" implementationClass = "BuildSupportPlugin" } + + register("androidApplicationCompose") { + id = "com.android.application.compose" + implementationClass = "AndroidApplicationComposeConventionPlugin" + } + register("androidLibraryCompose") { + id = "com.android.library.compose" + implementationClass = "AndroidLibraryComposeConventionPlugin" + } } } diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt new file mode 100644 index 0000000..c46c485 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt @@ -0,0 +1,36 @@ +import com.android.build.gradle.internal.dsl.BaseAppModuleExtension +import org.gradle.api.Project +import org.gradle.kotlin.dsl.getByType + +/** + * Android application compose convention plugin + * + * If compose is required, then: + * ``` + * plugins { + * id("com.android.application.compose") + * } + * ``` + * + * If not required: + * ``` + * plugins { + * id("com.android.application") + * } + * ``` + * + * @constructor Create empty Android application compose convention plugin + */ +class AndroidApplicationComposeConventionPlugin : BasePlugin() { + override fun apply(target: Project) { + log("apply target: ${target.displayName}") + with(target) { + if (!plugins.hasPlugin("com.android.application")) { + pluginManager.apply("com.android.application") + } + extensions.getByType().apply { + configureAndroidCompose(this) + } + } + } +} diff --git a/build-logic/convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt new file mode 100644 index 0000000..289291e --- /dev/null +++ b/build-logic/convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt @@ -0,0 +1,36 @@ +import com.android.build.gradle.LibraryExtension +import org.gradle.api.Project +import org.gradle.kotlin.dsl.getByType + +/** + * Android library compose convention plugin + * + * If compose is required, then: + * ``` + * plugins { + * id("com.android.library.compose") + * } + * ``` + * + * If not required: + * ``` + * plugins { + * id("com.android.library") + * } + * ``` + * + * @constructor Create empty Android library compose convention plugin + */ +class AndroidLibraryComposeConventionPlugin : BasePlugin() { + override fun apply(target: Project) { + log("apply target: ${target.displayName}") + with(target) { + if (!plugins.hasPlugin("com.android.library")) { + pluginManager.apply("com.android.library") + } + extensions.getByType().apply { + configureAndroidCompose(this) + } + } + } +} diff --git a/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt b/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt index c492442..0b8df4d 100644 --- a/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt +++ b/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt @@ -302,13 +302,4 @@ class BuildSupportPlugin : BasePlugin() { } } } - - private fun lintConfigure(): Lint.() -> Unit = { - abortOnError = true - warningsAsErrors = false - ignoreTestSources = true - checkDependencies = true - checkReleaseBuilds = false // Full lint runs as part of 'build' task. - htmlReport = true - } } diff --git a/build-logic/convention/src/main/kotlin/ProjectExt.kt b/build-logic/convention/src/main/kotlin/ProjectExt.kt new file mode 100644 index 0000000..bc8b5eb --- /dev/null +++ b/build-logic/convention/src/main/kotlin/ProjectExt.kt @@ -0,0 +1,46 @@ +import com.android.build.api.dsl.CommonExtension +import com.android.build.api.dsl.Lint +import org.gradle.api.Project +import org.gradle.api.plugins.PluginContainer +import org.gradle.kotlin.dsl.configure +import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension + +internal fun Project.lintConfigure(): Lint.() -> Unit = { + abortOnError = true + warningsAsErrors = false + ignoreTestSources = true + checkDependencies = true + checkReleaseBuilds = false // Full lint runs as part of 'build' task. + htmlReport = true + // baseline = rootProject.file("lint-config/lint-baseline.xml") + // lintConfig = rootProject.file("lint-config/lint-default.xml") +} + +internal fun PluginContainer.hasKotlinComposePlugin() = hasPlugin("org.jetbrains.kotlin.plugin.compose") + +/** + * Configure Compose-specific options + * + * @param commonExtension + * @param hasRedwood Is Redwood used? + */ +fun Project.configureAndroidCompose( + commonExtension: CommonExtension<*, *, *, *, *>, + hasRedwood: Boolean = true +) { + if (!plugins.hasKotlinComposePlugin()) { + pluginManager.apply("org.jetbrains.kotlin.plugin.compose") + } + + commonExtension.apply { + if (!hasRedwood) { + // If you are using Redwood, you do not need to set this parameter. + buildFeatures.compose = true + } + } + + extensions.configure { + enableStrongSkippingMode.set(true) + reportsDestination.set(layout.buildDirectory.dir("compose_compiler")) + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cc234a7..ea1211e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,6 +19,7 @@ junit = "4.13.2" gradlePlugin-android = { module = "com.android.tools.build:gradle", version.ref = "agp" } gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } gradlePlugin-spotless = "com.diffplug.spotless:spotless-plugin-gradle:6.25.0" +gradlePlugin-compose-compiler = { module = "org.jetbrains.kotlin:compose-compiler-gradle-plugin", version.ref = "kotlin" } androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core-ktx" } androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" } @@ -63,13 +64,18 @@ androidx-test-junit = { group = "androidx.test.ext", name = "junit", version.ref junit = { group = "junit", name = "junit", version.ref = "junit" } [plugins] +compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } + +android-application-compose = { id = "com.android.application.compose" } +android-library-compose = { id = "com.android.library.compose" } + android-application = { id = "com.android.application", version.ref = "agp" } android-library = { id = "com.android.library", version.ref = "agp" } + kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } kotlin-cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" } -jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "jbr-compose" } -compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } +jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "jbr-compose" } [bundles] asm = [] diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 4752c9a..e36139a 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -4,7 +4,7 @@ plugins { alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.kotlin.cocoapods) alias(libs.plugins.compose.compiler) - alias(libs.plugins.android.library) + alias(libs.plugins.android.library.compose) id("dev.icerock.mobile.multiplatform-resources") } From b751ab0a377b29325e56bdc490e61dab78b35cc3 Mon Sep 17 00:00:00 2001 From: nian1 Date: Tue, 9 Jul 2024 19:31:25 +0800 Subject: [PATCH 4/4] Update BuildSupportPlugin.kt --- build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt b/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt index 0b8df4d..e8f93bd 100644 --- a/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt +++ b/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt @@ -132,6 +132,7 @@ class BuildSupportPlugin : BasePlugin() { defaultConfig { minSdk = Versions.minSdk targetSdk = Versions.targetSdk + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } testOptions.animationsDisabled = true