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

Malformed generated Proguard rules for classes with data in package #624

Closed
mhelder opened this issue Jun 27, 2024 · 2 comments · Fixed by #626
Closed

Malformed generated Proguard rules for classes with data in package #624

mhelder opened this issue Jun 27, 2024 · 2 comments · Fixed by #626

Comments

@mhelder
Copy link
Contributor

mhelder commented Jun 27, 2024

This is a follow-up on #556.

I've updated the previously shared sample to use 0.27.1, but now seem to be running into #415:

> Task :app:minifyReleaseWithR8 FAILED
ERROR: <snip>/moshix-sealed-missing-proguard-rules/app/build/intermediates/generated_proguard_file/release/proguard.txt:10:1-27: R8: Expecting '-keep' option after '-if' option.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
   > Compilation failed to complete, position: Text range from: 'offset: 365, line: 10, column: 1', to: 'offset: 391, line: 10, column: 27', origin: <snip>/moshix-sealed-missing-proguard-rules/app/build/intermediates/generated_proguard_file/release/proguard.txt

Rules generated under resources/META-INF/proguard:

moshi-com.example.app.data.model.Message.Success.pro:

-if class com.example.app.data.model.Message$Success
-keepnames class com.example.app.data.model.Message$Success
-if class com.example.app.data.model.Message$Success
-keep class com.example.app.data.model.Message_SuccessJsonAdapter {
    public <init>(com.squareup.moshi.Moshi);
}

moshi-com.example.app.data.model.Message.pro:

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

Rules for the latter were previously missing (see #556), which was fixed in #603. (Thanks!).

However, note:

  • the escaped `data` in the package of the if clauses, causing the syntax to be malformed.
  • the invalid reference to the nested classes Success and Unknown: . instead of $.

Comparing the contents of the two files, it seems like the rules for the nested class Success itself are correctly generated , but not the sealed class in which it is nested.

In case it's relevant: the package declaration of the generated JsonAdapters also contains `data`:

package com.example.app.`data`.model`
@ZacSweers
Copy link
Owner

Thanks, I'll take a look. PR is welcome as well

@mhelder
Copy link
Contributor Author

mhelder commented Jun 27, 2024

I opened #626!

It looks like it wasn't just generating malformed rules for packages with reserved keywords, but also generating incorrect rules for nested classes.

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

Successfully merging a pull request may close this issue.

2 participants