Skip to content
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

Missing classes detected while running R8 / Proguard #297

Closed
MarcelReiter opened this issue Aug 3, 2023 · 6 comments · Fixed by #336 · May be fixed by #394
Closed

Missing classes detected while running R8 / Proguard #297

MarcelReiter opened this issue Aug 3, 2023 · 6 comments · Fixed by #336 · May be fixed by #394
Assignees
Labels
usage Build problems in client projects

Comments

@MarcelReiter
Copy link

Attempting to obfuscate and shrink any android app that uses Instant results in the following errors

Missing classes detected while running R8. 
Please add the missing classes or apply additional keep rules that are generated in
.../app/build/outputs/mapping/release/missing_rules.txt.

The file mentioned contains:

-dontwarn kotlinx.serialization.KSerializer
-dontwarn kotlinx.serialization.Serializable

To Reproduce

  1. Create a new Android app.
  2. Add the following dependency: implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0").
  3. Create a new class which includes a field that is of type "Instant" and use it somewhere.
  4. Attempt to obfuscate and shrink the app in release.

Minimal sample
See this github project: https://github.com/MarcelReiter/dateTimeTest
You NEED to build it in release mode.
Also i made nice small commits so it's understandable what i'm doing

Environment

  • Kotlin version: 1.8.10
  • Library version: 0.4.0
  • Kotlin platforms: Android JVM

A nearly identical issue has been created by someone else in the kotlinx.serialization github:
Kotlin/kotlinx.serialization#2392 - but it seems like it is kotlinx.datetime related

@matejbart
Copy link

The current kotlinx.datetime version 0.4.0 is based on kotlinx.serialization version 1.3.2, so one option is to explicitly bump the kotlinx.serialization version to the latest stable version 1.5.1 that already contains the proguard rules (see release notes v1.5.0-RC) to fix these issues.

@ilya-g
Copy link
Member

ilya-g commented Aug 28, 2023

@matejbart Not sure it would help. kotlinx-serialization is used as a compile time dependency in JVM variant of kotlinx-datetime and therefore is not propagated transitively to dependees, so it's irrelevant which rules it contains.

@MarcelReiter
Copy link
Author

I have updated to kotlinx.datetime 0.4.1 which includes an update of kotlinx.serialization to 1.5.1.
However, the issue still exists. Can someone confirm?

@dkhalanskyjb dkhalanskyjb added the usage Build problems in client projects label Dec 1, 2023
@VitaliyBelyaev
Copy link

VitaliyBelyaev commented Dec 15, 2023

I have updated to kotlinx.datetime to 0.5.0 which uses kotlinx.serialization 1.6.2 as I see in External libraries section in Android Studio, but issue with R8 still exists.

  • Android Studio Hedgehog | 2023.1.1 RC 1
  • Kotlin 1.9.21
  • Android Gradle Plugin 8.2.0

@VitaliyBelyaev
Copy link

As workaround, I've added kotlinx.serialization explicitly to the project: plugin and dependency version 1.6.2 to the android app and issue with R8 gone.

I think that proguard rules from kotlinx.serialization were applied and that fixed issue.

Maybe some or all rules from kotlinx.serialization should be added to kotlinx.datetime library for those who needs kotlinx.datetime but don't uses kotlinx.serialization.

@ilya-g
Copy link
Member

ilya-g commented Dec 15, 2023

I've added kotlinx.serialization explicitly to the project: plugin and dependency version 1.6.2 to the android app and issue with R8 gone.
I think that proguard rules from kotlinx.serialization were applied and that fixed issue.

The workaround helped because the classes that R8 reported as missing are now found in the kotlinx.serialization dependency you've added.

dkhalanskyjb added a commit that referenced this issue Jan 19, 2024
This permits using kotlinx-datetime without kotlinx-serialization
on Android without complaints from the build tooling.

Fixes #297
@dkhalanskyjb dkhalanskyjb self-assigned this Jan 19, 2024
dkhalanskyjb added a commit that referenced this issue Jan 22, 2024
This permits using kotlinx-datetime without kotlinx-serialization
on Android without complaints from the build tooling.

Fixes #297
dkhalanskyjb added a commit that referenced this issue Feb 13, 2024
This permits using kotlinx-datetime without kotlinx-serialization
on Android without complaints from the build tooling.

Fixes #297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usage Build problems in client projects
Projects
None yet
5 participants