Skip to content

Commit fc7e903

Browse files
authored
Fix ./gradlew runRelease, update ProGuard to 7.7.0 (#5279)
Fixes https://youtrack.jetbrains.com/issue/CMP-7577/Desktop-runRelease-crash-when-upgrade-to-CMP-1.8.0-alpha02 Fixes https://youtrack.jetbrains.com/issue/CMP-3818/Update-ProGuard-to-version-7.4-to-support-new-Java-versions Fixes https://youtrack.jetbrains.com/issue/CMP-4883/Default-Proguard-rules-cause-release-task-failure-when-using-Material-3-instead-of-2-in-Compose-Desktop Targeting 1.8.0 The rules was added by testing our current examples. The comprehensive rules are only possible if we run [all tests with ProGuard](https://youtrack.jetbrains.com/issue/CMP-3404/Run-all-Compose-tests-with-ProGuard-on). Also, each rule wasn't investigated thoroughly, in some cases it might a valid rule, in some cases a ProGuard bug. The auto integration checks on CI will be added in https://youtrack.jetbrains.com/issue/CMP-7970/Add-integration-checks-for-all-libraries. ## Testing `./gradlew runRelease` works in: - https://kmp.jetbrains.com - all examples ## Release Notes ### Features - Desktop - The default ProGuard version is set to 7.7.0 - If there are any new errors in the release build, update [the ProGuard rules](https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-native-distribution.html#minification-and-obfuscation) - A usual workaround is to add `-keep class` for the associated with error class in "Location:" - If the error contains `androidx.` package, it might a Compose bug, please report in https://youtrack.jetbrains.com/issues/CMP. The `-keep class` workaround should also work in this case. - _(prerelease fix)_ `./gradlew runRelease` doesn't crash with `java.lang.VerifyError`
1 parent 70bf5f1 commit fc7e903

File tree

7 files changed

+28
-6
lines changed

7 files changed

+28
-6
lines changed

examples/imageviewer/desktopApp/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,9 @@ compose.desktop {
3939
iconFile.set(iconsRoot.resolve("icon-linux.png"))
4040
}
4141
}
42+
43+
buildTypes.release.proguard {
44+
configurationFiles.from(project.file("rules.pro"))
45+
}
4246
}
4347
}

examples/imageviewer/desktopApp/rules.pro

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
-keep class io.ktor.** { *; }
33
-keepclassmembers class io.ktor.** { volatile <fields>; }
44
-keep class io.ktor.client.engine.cio.** { *; }
5-
-keep class kotlinx.coroutines.** { *; }
65
-dontwarn kotlinx.atomicfu.**
76
-dontwarn io.netty.**
87
-dontwarn com.typesafe.**
98
-dontwarn org.slf4j.**
10-
11-
# Obfuscation breaks coroutines/ktor for some reason
12-
-dontobfuscate
9+
-dontnote io.ktor.**
10+
-dontnote org.slf4j.**
11+
-dontnote kotlinx.serialization.**

examples/issues/desktop/compose-desktop.pro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@
1313
-dontwarn org.bouncycastle.**
1414
-dontwarn org.openjsse.**
1515

16-
-keep class org.ocpsoft.prettytime.i18n**
16+
-keep class org.ocpsoft.prettytime.i18n**
17+
18+
-dontnote okhttp3.**
19+
-keep class okio.Okio__JvmOkioKt { *; }

examples/nav_cupcake/composeApp/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ compose.desktop {
141141
packageName = "org.jetbrains.nav_cupcake"
142142
packageVersion = "1.0.0"
143143
}
144+
145+
buildTypes.release.proguard {
146+
configurationFiles.from(project.file("rules.pro"))
147+
}
144148
}
145149
}
146150

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-keep enum org.jetbrains.nav_cupcake.** { *; }

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ProguardSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.jetbrains.compose.internal.utils.notNullProperty
1212
import org.jetbrains.compose.internal.utils.nullableProperty
1313
import javax.inject.Inject
1414

15-
private const val DEFAULT_PROGUARD_VERSION = "7.2.2"
15+
private const val DEFAULT_PROGUARD_VERSION = "7.7.0"
1616

1717
abstract class ProguardSettings @Inject constructor(
1818
objects: ObjectFactory,

gradle-plugins/compose/src/main/resources/default-compose-desktop-rules.pro

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
-dontwarn java.lang.ClassValue
3030
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
3131

32+
# https://youtrack.jetbrains.com/issue/CMP-3818/Update-ProGuard-to-version-7.4-to-support-new-Java-versions
33+
# https://youtrack.jetbrains.com/issue/CMP-7577/Desktop-runRelease-crash-when-upgrade-to-CMP-1.8.0-alpha02
34+
-keep,allowshrinking,allowobfuscation class kotlinx.coroutines.flow.FlowKt { *; }
35+
-keep,allowshrinking,allowobfuscation class kotlinx.coroutines.Job { *; }
36+
-dontnote kotlinx.coroutines.**
37+
38+
# org.jetbrains.kotlinx:kotlinx-coroutines-swing
39+
-keep class kotlinx.coroutines.swing.SwingDispatcherFactory
40+
3241
# Kotlinx Datetime
3342
# Material3 depends on it, and it references `kotlinx.serialization`, which is optional
3443
# Copied from https://github.com/Kotlin/kotlinx-datetime/blob/v0.6.2/core/jvm/resources/META-INF/proguard/datetime.pro
@@ -56,4 +65,6 @@
5665
-dontwarn org.graalvm.compiler.core.aarch64.AArch64NodeMatchRules_MatchStatementSet*
5766

5867
# Androidx
68+
-keep,allowshrinking,allowobfuscation class androidx.compose.runtime.SnapshotStateKt__DerivedStateKt { *; }
69+
-keep class androidx.compose.material3.SliderDefaults { *; }
5970
-dontnote androidx.**

0 commit comments

Comments
 (0)