-
Notifications
You must be signed in to change notification settings - Fork 613
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
ProGuard rules are too strict #1129
Comments
I'm using
which is a bit more general but potentially not as permissive with regard to obfuscation (as i don't obfuscate). Perhaps we could combine and embed the rules so that they're applied automatically (similar to what we've done with coroutines, and many other libraries). |
What's the difference from the current proguard configuration? I can see only Also, line @jw Am I right that
allows to keep all the |
Yes. It assumes the companion is named The first issue could probably be fixed by replacing |
@sandwwraith I didn't realized the support of named companions. In that case the classes cannot be obfuscated. However, I don't think Obfuscation is important to me and is actually one of the reasons I migrated from Moshi as the Moshi codegen generates ProGuard rules that prevent obfuscation. I don't think there is any ways to exclude part of the rules from libraries, so I would prefer not embedding the rules as they are intrusive (they affect user code and cannot be disabled). |
Was there any decision / progress made on this? |
On a similar vein, what is the purpose/requirement for this rule?
This seems like it would be keeping EVERY Companion object's classmembers, even if they aren't using Kotlin Serialization? Is that really necessary? |
kotlinx.serialization/core/jvmMain/src/kotlinx/serialization/internal/Platform.kt Lines 47 to 52 in afc3bed
Seems that we need only keep the name of serializers without |
Hi!
Serialization supports named companions but for such classes it is necessary to add an additional rule.
This rule keep serializer and serializable class from obfuscation. Therefore, it is recommended not to use wildcards in it, but to write rules for each such class. |
@shanshin Appreciate the updated rules. These seemed to work for us as well. Only correction I think that would need to be made is in the if statement that you provided.
The class found in the if statement will be held in the |
@dustinsummers, can you recheck this, please? |
According this |
Actually I'm specifying the serializers of all json classes in my project manually so that I don't need any proguard rules. val json = Json {
serializersModule = SerializersModule {
contextual(JsonClass1.serializer())
contextual(JsonClass2.serializer())
}
} |
Now the rules apply only for classes marked as @serializable Resolves #1129
Now the rules apply only for classes marked as @serializable Resolves #1129
@shanshin Was @ArcticLampyrid 's suggestion accidentally overlooked? I'm not really familiar with ProGuard rules, but at a glance it seems much more intuitive. I was browsing through ProGuard's documentation to figure out why I wouldn't be able to apply this rule to all
... seems to take care of. I thus suspect this comment was overlooked and the current rules are still more complicated than they have to be. |
@Whathecode
|
@mxalbert1996 this was only a partial copy of the full suggestion by @ArcticLampyrid to highlight at least part of the configuration I understood made more sense to me. Sorry if that wasn't clear. |
Now the rules apply only for classes marked as @serializable Resolves Kotlin#1129
The ProGuard rules in the README are so strict that they prevent json model classes and generated serializer classes from being optimized and obfuscated.
After some tests, these seem enough:
The first rule keeps the
Companion
field and the Companion class of json model classes. The field cannot be renamed because of the reflection usage but its class can. This rule does not prevent the model class itself and its Companion class from being obfuscated.The second rule keeps the
serializer()
method of the Companion class of json model classes. This method also cannot be renamed because of this. Since this method will return the serializer instance for this model class, the specific serializer class will also be kept. Serializer classes don't use reflection so they (including their fields and methods) can be obfuscated and this rule does not prevent that.If this looks good to you, I'm glad to submit a PR.
The text was updated successfully, but these errors were encountered: