-
Notifications
You must be signed in to change notification settings - Fork 636
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
R8 task fails with missing StringConcatFactory when using AGP 8.0 #2145
Comments
Just to clarify this comment on the bug I would like to understand why the use of the If the |
@shanshin The recently shipped consumer proguard rules in 1.5.0-RC should have included a fix for this issue too |
It still seems to be an issue even on 1.5.0 stable. |
Same issue with |
still facing this issue with latest kotlinx-serialization (1.5.1) version |
Facing this issue with Gradle 8 and latest kotlinx-serialization (1.5.1) version. |
Facing this issue with AGP 8.0.1 and latest kotlinx-serialization version. Did anybody find any issues ? I am using JDK 11 for building |
is there any plans to fix this soon? |
Hi, Adding a common It would be really nice for us to have a user-defined reproducer (in any form that we can checkout & run), so we can understand the root cause of the problem and to pinpoint it instead of potentially treating the symptoms |
let me try to reproduce the issue on a sample project and share it with you, probably next week |
I have researched around the source code of |
same issue, any solution ? |
It actually depends what's using StringConcatFactory in your code. For me, the solution I suggested actually works to mitigate the issue. |
Unfortunately we're unable to reproduce the problem on a clean project. Grepping decompiled JAR files of kotlinx.serialization also does not show any usages of |
If you take a look at the issue description and the related Google's bug tracker, you will be able to understand that StringConcatFactory is not required to be directly used in Kotlinx.serialization to result in this problem |
In that case, what is the connection between kotlinx.serialization and this problem? Compiler plugin can't produce calls on |
StringConcatFactory is used for concatenating strings. Each time we are using formatted strings: "$param string", this translates into the StringConcat call on java. Take my hypothesis with a grain of salt as I'm not an expert either, just researched a bit |
This is correct. It also means that Kotlin compiler produces this call, and not kotlinx.serialization. |
I suspect that this problem is caused by incorrect configuration. If you have these lines:
It means that Kotlin configured to produce Java11 bytecode. In that case, it will emit calls to StringConcatFactory. |
What if you need to target 11? What makes this configuration incorrect? |
Then how do you expect this code to run on Android? |
Why is it logical to have users of the library provide proguard rules for that library? |
It would normally be logical to add rules required for a library to the library. The main reason for not adding rules like |
@Nek-12 As I said, kotlinx.serialization does not require that rules. Your code (compiled with jvmTarget = 11) does. Therefore, as author of the library, you should provide the rules :) |
Finally spend dome time to actually figure out where this warning is coming from, see https://issuetracker.google.com/250197571#comment25. As it has nothing to do with Kotlin Serialization so adding the suggested The I think this can be closed as working as intended. |
@sgjesse Thank you very much for clear and detailed explanation, that's exactly what I was trying to say. |
An alternative to using the
AGP already turns off off generation of |
Issue at Google tracker about adding |
I am using @keep annotation and getting this issue on that data class where it was applied. Do you have any idea for actual fix? I added UPDATE: It seems the issue after adding such rule is a bug from Android. The checker is contradicting to what it should actually do. |
This worked, thanks |
When I add
Any advice on how to resolve this? Thank you! |
Sorry, but I only tested with Kotlin Script ( |
with build.gradle.kts in Android (in 2024), I needed: |
Describe the bug
I've had an issue with R8 task failing because the StringConcatFactory rule was missing in my proguard-rules.pro.
Agp now treats missing classes as errors since 8.0, and kotlinx.serialization utilizes StringConcatFactory which R8 then is unable to find because it's stripped from the actual code (sanitized away when targeting jvm 8+)
Please find exact details of the discussion in the following topic https://issuetracker.google.com/issues/250197571#comment19
The conclusion me and the Google team arrived at is that libraries should specify a
-dontwarn
rule for such cases.This ticket is therefore a request to add the missing rules.
To Reproduce
Compile a library android module that uses kotlinx.serialization and targets jdk 11 on AGP 8.0-alpha. Compilation will fail.
Expected behavior
Environment
The text was updated successfully, but these errors were encountered: