Skip to content

Bundle kotlinx serialization ProGuard rules into the Compose plugin#5314

Merged
Igor Demin (igordmn) merged 1 commit into
masterfrom
igor.demin/fix-serialization-rules
May 12, 2025
Merged

Bundle kotlinx serialization ProGuard rules into the Compose plugin#5314
Igor Demin (igordmn) merged 1 commit into
masterfrom
igor.demin/fix-serialization-rules

Conversation

@igordmn

@igordmn Igor Demin (igordmn) commented May 9, 2025

Copy link
Copy Markdown
Collaborator

When users use androidx.navigation, they see @Serialization annotation they can use, without explictly adding kotlinx.serialization. They see, because it is added as an api dependency.

The Compose Gradle plugin on the other hand provide ./gradlew runRelease task that uses ProGuard to minify binaries. Because the plugin should support not only Compose, but also all support libraries (androidx, components), we should bundle serialization ProGuard rules into it.

Fixes https://youtrack.jetbrains.com/issue/CMP-8050

Testing

import androidx.compose.ui.window.singleWindowApplication
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController

fun main() = singleWindowApplication {
    NavHost(
        navController = rememberNavController(),
        startDestination = LoginRoute()
    ) {
        composable<LoginRoute> {}
    }
}

sealed interface Route

@kotlinx.serialization.Serializable
data class LoginRoute(val id: Long? = null) : Route

Doesn't crash when run ./gradlew runRelease

Release Notes

Fixes - Desktop

  • Fix "Serializer for class is not found" using androidx.navigation and running ./gradlew runRelease
  • kotlinx.serialization ProGuard rules are bundled in the Compose Gradle plugin

Reasoning to bundle:
- Compose Gradle plugin should support Compose and all support libraries (androidx, components)
- `androidx.navigation` exposes `kotlinx.serialization` as API

Fixes https://youtrack.jetbrains.com/issue/CMP-8050

## Testing
```
import androidx.compose.ui.window.singleWindowApplication
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController

fun main() = singleWindowApplication {
    NavHost(
        navController = rememberNavController(),
        startDestination = LoginRoute()
    ) {
        composable<LoginRoute> {}
    }
}

sealed interface Route

@kotlinx.serialization.Serializable
data class LoginRoute(val id: Long? = null) : Route
```
Doesn't crash

## Release Notes
### Fixes - Desktop
- Fix "Serializer for class is not found" using `androidx.navigation` and running `./gradlew runRelease`
@igordmn Igor Demin (igordmn) changed the title Bundle kotlinx serialization rules into the Compose plugin Bundle kotlinx serialization ProGuard rules into the Compose plugin May 9, 2025

@MatkovIvan Ivan Matkov (MatkovIvan) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we track such rules per-module bases?
Can we re-use ones from AOSP (automatically)?

@igordmn

Copy link
Copy Markdown
Collaborator Author

Can we re-use ones from AOSP

I am not aware of androidx-specific rules besides small # Androidx section. It is not worth to implement just for it. The issues are with external dependencies (Kotlin/Kotlinx).

https://youtrack.jetbrains.com/issue/CMP-7777/Support-ProGuard-rules-bundled-in-libraries should allow to read the bundled rules.

@igordmn Igor Demin (igordmn) merged commit bffb159 into master May 12, 2025
15 of 16 checks passed
@igordmn Igor Demin (igordmn) deleted the igor.demin/fix-serialization-rules branch May 12, 2025 11:59
Igor Demin (igordmn) added a commit that referenced this pull request May 12, 2025
…5314)

When users use `androidx.navigation`, they see `@Serialization`
annotation they can use, without explictly adding
`kotlinx.serialization`. They see, because it is added as an `api`
dependency.

The Compose Gradle plugin on the other hand provide `./gradlew
runRelease` task that uses ProGuard to minify binaries. Because the
plugin should support not only Compose, but also all support libraries
(androidx, components), we should bundle serialization ProGuard rules
into it.

Fixes https://youtrack.jetbrains.com/issue/CMP-8050

## Testing
```
import androidx.compose.ui.window.singleWindowApplication
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController

fun main() = singleWindowApplication {
    NavHost(
        navController = rememberNavController(),
        startDestination = LoginRoute()
    ) {
        composable<LoginRoute> {}
    }
}

sealed interface Route

@kotlinx.serialization.Serializable
data class LoginRoute(val id: Long? = null) : Route
```
Doesn't crash when run `./gradlew runRelease`

## Release Notes
### Fixes - Desktop
- Fix "Serializer for class is not found" using `androidx.navigation`
and running `./gradlew runRelease`
- `kotlinx.serialization` ProGuard rules are bundled in the Compose
Gradle plugin

(cherry picked from commit bffb159)
Vlad Konstantinov (Kpotko) pushed a commit that referenced this pull request May 12, 2025
…mpose plugin (#5314) (#5317)

Cherry-pick of
#5314

## Release Notes
N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants