Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,14 @@ abstract class ComposeCompilerGradlePluginExtension @Inject internal constructor
if (nonSkippingGroupsOptimization) features + ComposeFeatureFlag.OptimizeNonSkippingGroups else features
}
)

/**
* Enable addition of Compose-specific entries to the proguard mapping file
* produced by optimizers (such as R8) when compiling Android applications.
* These entries are used to deobfuscate group key based Compose stack traces
* in minified applications.
*
* Enabled by default.
*/
val includeComposeMappingFile: Property<Boolean> = objectFactory.property(Boolean::class.java).convention(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ComposeCompilerGradleSubplugin : KotlinCompilerPluginSupportPlugin {

override fun apply(target: Project) {
composeExtension = target.extensions.create("composeCompiler", ComposeCompilerGradlePluginExtension::class.java)
target.configureComposeMappingFile()
target.configureComposeMappingFile(enabled = composeExtension.includeComposeMappingFile)
}

override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.gradle.api.file.Directory
import org.gradle.api.file.RegularFile
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.register
Expand All @@ -33,7 +34,9 @@ import java.util.zip.ZipFile
import javax.inject.Inject


internal fun Project.configureComposeMappingFile() {
internal fun Project.configureComposeMappingFile(
enabled: Property<Boolean>
) {
plugins.withId("com.android.application") {
val configuration = configurations.maybeCreate("composeMappingProducerClasspath")
.also {
Expand All @@ -46,6 +49,7 @@ internal fun Project.configureComposeMappingFile() {
}

extensions.findByType<ApplicationAndroidComponentsExtension>()?.onVariants { variant ->
if (!enabled.get()) return@onVariants
if (!variant.isMinifyEnabled) return@onVariants

val name = variant.name.capitalize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ dependencies {
testApi(project(":compiler:tests-mutes:mutes-junit5"))

testCompileOnly(libs.intellij.asm)

testImplementation(project(":compose-compiler-gradle-plugin"))
}

tasks.register<Delete>("cleanTestKitCache") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ package org.jetbrains.kotlin.gradle

import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.configuration.WarningMode
import org.gradle.kotlin.dsl.getByType
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension
import org.jetbrains.kotlin.gradle.testbase.*
import org.jetbrains.kotlin.test.TestMetadata
import org.junit.jupiter.api.DisplayName
Expand Down Expand Up @@ -715,6 +715,46 @@ class ComposeIT : KGPBaseTest() {
}
}

@DisplayName("Minified app with disabled mapping does not run Compose tasks.")
@AndroidGradlePluginTests
@GradleAndroidTest
@DisabledOnOs(
OS.WINDOWS, disabledReason = "AGP contains a bug that prevents test output files from being cleaned up on Windows. " +
"See: https://issuetracker.google.com/issues/445967244"
)
@TestMetadata("AndroidSimpleComposeApp")
fun testMinifyWithComposeDisabled(
gradleVersion: GradleVersion,
agpVersion: String,
providedJdk: JdkVersions.ProvidedJdk
) {
project(
projectName = "AndroidSimpleComposeApp",
gradleVersion = gradleVersion,
buildJdk = providedJdk.location,
buildOptions = defaultBuildOptions
.copy(androidVersion = agpVersion)
) {
buildScriptInjection {
val appExtension = project.extensions.getByType<ApplicationAndroidComponentsExtension>()
appExtension.beforeVariants {
if (it.name == "release") {
it.isMinifyEnabled = true
}
}
val composeExtension = project.extensions.getByType<ComposeCompilerGradlePluginExtension>()
composeExtension.includeComposeMappingFile.set(false)
}

build("assembleRelease") {
assertTasksAreNotInTaskGraph(
":produceReleaseComposeMapping",
":mergeReleaseComposeMapping"
)
}
}
}

private fun Path.appendComposePlugin() {
modify { originalBuildScript ->
"""
Expand Down