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

MoshiX generates malformed proguard rule #415

Closed
sav007 opened this issue Apr 17, 2023 · 7 comments
Closed

MoshiX generates malformed proguard rule #415

sav007 opened this issue Apr 17, 2023 · 7 comments

Comments

@sav007
Copy link

sav007 commented Apr 17, 2023

Latest version of MoshiX sealed leads to malformed proguard rules.
The cause of issue was the data package name like: com.example.data

The generated proguard rule:

# Conditionally keep this adapter for every possible nested subtype that uses it.
-if class com.example.`data`.Model
-keep class com.example.data.ModelJsonAdapter {
    public <init>(com.squareup.moshi.Moshi);
}

Error:

AGPBI: {"kind":"error","text":"Expecting '-keep' option after '-if' option.","sources":[{"file":".../build/intermediates/consumer_proguard_dir/release/lib0/proguard.txt","position":{"startLine":57,"startColumn":0,"startOffset":2994,"endColumn":41,"endOffset":3035}}],"tool":"R8"}

Not 100% sure what the cause of this but it looks like KotlinPoet changed the returned value in reflectionName():

@ZacSweers
Copy link
Owner

Which version of Kotlinpoet are you using?

@sav007
Copy link
Author

sav007 commented Apr 18, 2023

We tried the latest one 1.13.0, but I believe we saw similar with 1.12.0, but not quite sure I have to double check as it might that some other library that uses KPoet updated it to 1.13.0.

Btw, the way how we addressed this issue in our project is to avoid using data in the name of package.

@ZacSweers
Copy link
Owner

Got it. This is a Kotlinpoet bug, so could you please file there? The reflection name should not be escaped

@sav007
Copy link
Author

sav007 commented Apr 18, 2023

Yeah, I guess you are right will reference this one in that issue.

@sav007
Copy link
Author

sav007 commented Apr 18, 2023

I wasn't able to reproduce this issue with plain KPoet, but have one guess:

  1. If you create a class like ClassName("com.sample.data", "Model").reflectionName() it returns the name without escaping: com.sample.data.Model
  2. But if you call on that class toString ClassName("com.sample.data", "Model").toString() it returns an escaped string com.sample.'data'.Model
  3. Next if you create class name with a escaped string like ClassName("", "com.sample.data.Model").reflectionName() then it returns escaped com.sample.'data'.Model

That makes me think if there any possible transformation in the codegen that leads to passing targetClass:ClassName with escaped package name to ProguardConfig. It might be a case where ClassName has been created with escaped package name somewhere ?

I also tried to reproduce the original issue in MoshiSealedSymbolProcessorProviderTest but no luck, though I see a little different result. If I change the test fixture to package test.data the generated adapter content is following:

// Code generated by moshi-sealed. Do not edit.
package test.`data`
....

even this valid source code, but I guess it should be non escaped package name.

I still will try to repro issue we see in our project with escaped proguard rule, but does above ^^^ give any idea where the issue is?

@ZacSweers
Copy link
Owner

I did not understand your third bullet, maybe because the formatting broke. Why would you make a class like ClassName("", "com.sample.data.Model")? That seems like a programmer error

@ZacSweers
Copy link
Owner

Closing as wontfix as there's been no followup

@ZacSweers ZacSweers closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2024
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

2 participants