-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Add annotation processor for generating keep rules for types mentioned only inside generics #3588
Comments
Even after adding rule:
|
Anyone :) ? It's pretty important. |
I have a similar issue with gradle plugin 4.2.1. Have you figured out what the issue is? |
No, I'm still waiting for a response. Downgrading to gradle 4.1.3 is the best option right now. |
It's strange, but simply downgrading to gradle 4.1.3 is not working for me |
In my case it was caused by data structure being removed by proguard, so adding the @keep annotation helped me |
You used @keep on some class or whole code? |
On a class, the signature I've got is similar to this: And adding the |
I have similar issue with Retrofit 2.9 (checked versions down to 2.6.2 too) and gradle plugin 4.2.2 with minifyEnabled=true
Downgrading plugin to |
Updating plugin to (Android Studio Arctic Fox | 2020.3.1 Patch 1) |
Thanks, that worked. For that reason I'm not closing this issue yet, because it should be possible using 4.x |
If something changed solely with an AGP version change then it's like a result of a newer version of R8. The easiest way for me to look at the problem would be a minimal, self-contained sample project that exhibits the problem. |
Though using 7.0.1 I've discovered new issue, but it's not leading to a crash like before. But I'll be hard to reproduce on your side probably. I have an api call to receive a list of items (for example articles), inside a model I have an object named PagingInfo - it's a simple class containing information about number of items and if there's more of the to get. When I'm using 7.0.1 this class becomes null in ALL api calls I have, but only when using R8. If I disable R8 it's working fine. Could this a GSON issue? I fixed the issue like this:
Class looks like this:
Inside a JSON response this looks like this:
I have tons of models and api calls - everything but this one works completely fine. But by some reason using 7.0.1 and R8 leads to retrofit (or gson) unable to deserialise this one class. Simply disabling R8, adding an exception in proguard file or rolling back to the older gradle plugin solves the issue. |
@JakeWharton here's a repro:
Expected: Activity starts and reads the header:
Actual:
Notable points on what makes it work:
I think this is a valid scenario in ProGuard/R8, it just removes an unused class. No-on ever accesses the class except that erased generics. Although the fix in future versions might be that generics -> used. |
Thank you for the excellent repro. I don't think there's any way to mitigate this from Retrofit's side with a simple keep rule. On Cash App we actually wrote an annotation processor which generates |
@JakeWharton while I'd love to see that for its tech, I'm not sure that would solve the problem.
This issue only affects a specific version range (R8 bundled into AGP 4.2.x) in a specific edge case (not using a return value). So the effort in making an annotation processor and advertising it is probably too much? (Note: the original title was good SEO.) |
That said, adjusting the error message might be useful, because retrace is not helpful here if you have many retrofit interfaces. (click to expand for what I tried)
|
When running R8 in full mode all generic types are removed unless they are explicitly kept. Retrofit automatically keeps the generic part for users of |
Hmm, that's a good point, thanks for clarifying. I just checked the rx1 and rx3 adapters in this repo, and they have keep rules. Just to understad more, is your proposal to replace those with more explicit ones generated by apt? |
Those rules are painful. It bloats the APK since those types are likely widespread in your application. Not sure we can safely remove them at this point–even with the processor. |
I've created another bug / question? #3774 but I'm not sure if I should have just wrote here. Looking at the proguard rules here:
It seems to me the rules for Single and other RX are already there. And I have an So what is it missing on my part? Couldn't find any documentation about this. |
hi jake, i have the experience of using APT and java poet to generate files in compile time .here is the PR i wrote for eventbus(greenrobot/EventBus#714) |
This is fully built internally at Cash App. We've used it for a few years. It only needs moved into open source. |
Doing this next week for 2.10. |
Otherwise they will be removed by R8 since it cannot determine whether we are doing reflection on them.
Old issue below:
Using com.squareup.retrofit2:retrofit:2.9.0
After upgrading gradle plugin from
to
I'm getting following error when running with minifyEnabled true:
Here's how looks the method, which generates the error:
In order to fix this I have to either:
I've read the docs about gradle 4.2 changes and nothing seems to be related to proguard directly.
Can someone explain what's going on?
The text was updated successfully, but these errors were encountered: