Skip to content

Bundle kotlinx serialization ProGuard rules into the Compose plugin #5314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025

Conversation

igordmn
Copy link
Collaborator

@igordmn igordmn commented May 9, 2025

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 igordmn requested a review from terrakok May 9, 2025 20:13
@igordmn igordmn changed the title Bundle kotlinx serialization rules into the Compose plugin Bundle kotlinx serialization ProGuard rules into the Compose plugin May 9, 2025
Copy link
Member

@MatkovIvan MatkovIvan left a comment

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
Collaborator Author

igordmn commented May 12, 2025

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 igordmn merged commit bffb159 into master May 12, 2025
15 of 16 checks passed
@igordmn igordmn deleted the igor.demin/fix-serialization-rules branch May 12, 2025 11:59
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)
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