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 adapters in AGP 7.4 with Moshi-ir codegen. #396

Closed
hrach opened this issue Mar 6, 2023 · 11 comments
Closed

Missing adapters in AGP 7.4 with Moshi-ir codegen. #396

hrach opened this issue Mar 6, 2023 · 11 comments

Comments

@hrach
Copy link

hrach commented Mar 6, 2023

Hi, we have a problem with R8 minification and JsonAdapters missing in the build (generated by moshi ir). Do you have any idea where the issue can be? I've tried searching issuetracker.google.com and here, but haven't found anything useful.

Started being broken after the update to AGP 7.3.2->7.4.2:

Libs used:

  • Gradle 8.0.2
  • AGP 7.4.2
  • R8 4.0.52 (implicit)
  • MoshiX 0.21.0
  • Moshi 1.14.0

Error:

 Caused by: java.lang.ClassNotFoundException: com.xxxx.BatchRequestJsonAdapter

This fixes it for us:

-keep class com.xxx.**.*JsonAdapter { *; }
@ZacSweers
Copy link
Owner

Can you put together a minimally reproducing sample? I can't help much without one

@apramana
Copy link

apramana commented Mar 7, 2023

Interesting, I saw adapters disappear after updating Gradle 7.6 -> 8.0.0

@hrach
Copy link
Author

hrach commented Mar 7, 2023

We did Gradle 8 update as well. So maybe I've just wrongly debugged the issue. How did you solve the mising adapters with Gradle 8?

@hrach
Copy link
Author

hrach commented Mar 7, 2023

Okay. I have a reproduction. Basically it seems to be triggered by using "realm-android" plugin with its new transformer API, which is a must for Gradle 8.0. Just adding the plugin makes the release build type crash with a missing adapter. Attaching repro. Disabling minification "fixes it".

moshigradlecrash.zip

@hrach
Copy link
Author

hrach commented Mar 30, 2023

Didn't you have a chance to take a look at the reproduction? Thank you.

@ZacSweers
Copy link
Owner

Your repro doesn't have any instructions on how to build it and contains no gradle wrapper files. I added some and see the same behavior. I think you answered it for yourself - the realm plugin is somehow removing or losing the generated adapter class. You should file a bug with them, this isn't a moshi-ir issue

@ZacSweers ZacSweers closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2023
@rorbech
Copy link

rorbech commented Apr 13, 2023

@ZacSweers The proguard configuration created from the MoshiX-plugin is not registered as input for the mergeReleaseGeneratedProguardFiles task when applying the version of the realm-plugin that uses the new transformer API (see realm/realm-java#7798 (comment) for details). Could it be that the task is not registered properly for the new transformer pipeline, or do you know the convention around how to propagate stuff like additional proguard rules through that?

@ZacSweers
Copy link
Owner

I am not familiar with realm or the transformer API it's using

@rorbech
Copy link

rorbech commented Apr 14, 2023

The transformer API is part of Android Gradle Plugin, so not Realm specific. The task infrastructure was reworked quite heavily from AGP 7.2 -> 7.4, so I just suspect that the conventions for locating ProcessResources-task in https://github.com/ZacSweers/MoshiX/blob/main/moshi-ir/moshi-gradle-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/gradle/MoshiGradleSubplugin.kt#L76 is not compatible with the possible variances in the task graph with AGP 7.4+.

@ZacSweers
Copy link
Owner

We are using it with AGP 7.4 and 8.0 without issues. This also only appears to occur when the realm plugin is applied and not with any other plugins (we have some bytecode processing plugins at my work). I'm not against fixing a bug if there is one here, but currently I'm not seeing it or an obvious better thing to do :/

@rorbech
Copy link

rorbech commented Apr 14, 2023

Might be that we are not forwarding the inputs/outputs correctly in the new pipeline, but I just couldn't see any paths, API or conventions around handling things other than the ones intended to go into the final jar. Will have to debug and see the various pieces in action to get an idea of what is missing in wiring it up.

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

No branches or pull requests

4 participants