8000 Remove outdated android-proguard-example by Goooler · Pull Request #2843 · google/gson · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove outdated android-proguard-example #2843

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

Merged
merged 9 commits into from
Apr 14, 2025

Conversation

Goooler
Copy link
Contributor
@Goooler Goooler commented Apr 12, 2025

Purpose

Closes #2718.

Checklist

  • New code follows the Google Java Style Guide
    This is automatically checked by mvn verify, but can also be checked on its own using mvn spotless:check.
    Style violations can be fixed using mvn spotless:apply; this can be done in a separate commit to verify that it did not cause undesired changes.
  • If necessary, new public API validates arguments, for example rejects null
  • New public API has Javadoc
    • Javadoc uses @since $next-version$
      ($next-version$ is a special placeholder which is automatically replaced during release)
  • If necessary, new unit tests have been added
    • Assertions in unit tests use Truth, see existing tests
    • No JUnit 3 features are used (such as extending class TestCase)
    • If this pull request fixes a bug, a new test was added for a situation which failed previously and is now fixed
  • mvn clean verify javadoc:jar passes without errors

@@ -393,3 +396,11 @@ For backward compatibility it is possible to restore Gson's old behavior of allo

- This does not solve any of the type-safety problems mentioned above; in the long term you should prefer one of the other solutions listed above. This system property might be removed in future Gson versions.
- You should only ever set the property to `"true"`, but never to any other value or manually clear it. Otherwise this might counteract any libraries you are using which might have deliberately set the system property because they rely on its behavior.

## R8 / ProGuard
Copy link
Contributor Author
@Goooler Goooler Apr 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't apply ## <a id="r8-proguard"></a> R8 / ProGuard for this header like the others, as the index of it (#a-idr8-proguarda-r8--proguard) can't be honored correctly by GitHub web.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that specific to this header? Because for the others GitHub UI seems to ignore the <a> when deriving the default anchor name (or it only seems to prepend a -).

If possible I think a stable anchor with <a> would be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems all existing ones are invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That rather looks like an issue with IntelliJ. In GitHub both anchors work:

  • GitHub derived one (also used for the "🔗" icon next to the title):
    #-proguard--r8
  • The one assigned with <a> (which should be referred to within the guide)
    #proguard-r8

(though maybe for GitHub this also relies on implementation details to some extent)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep the header without id, it works for both IDEA and GitHub. But I can update the style if you want.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IntelliJ (IntelliJ IDEA 2024.3.5) seems to be a bit inconsistent. Code completion for Markdown links suggests these #a-idr8-proguarda-r8--proguard anchors you mentioned. However, for the Markdown preview the custom <a> anchor links seem to work fine within the same document. But they do not work between different files, e.g. the link from the README to the Troubleshooting guide section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the same behavior as IDEA 2025.1

Copy link
Collaborator
@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this! I have added some small comments.

Maybe the R8 / ProGuard section needs to be expanded:

  • it should only say "no additional ProGuard configuration is needed"
    • because the Java code of the users needs to adhere to a specific pattern (see below)
    • and only "in most cases", there are some corner cases (example)
  • it should document requirements for user classes
    • classes must have a no-args constructor, and must be either top-level or static (to avoid additional implicit constructor args)
    • fields must be annotated with @SerializedName
  • maybe it should mention that ProGuard for non-Android projects has to configure the gson.pro file manually, see META-INF/proguard/*.pro files only recognized by Android plugin Guardsquare/proguard#337

If you want I can do that in a follow-up pull request instead though.

@@ -393,3 +396,11 @@ For backward compatibility it is possible to restore Gson's old behavior of allo

- This does not solve any of the type-safety problems mentioned above; in the long term you should prefer one of the other solutions listed above. This system property might be removed in future Gson versions.
- You should only ever set the property to `"true"`, but never to any other value or manually clear it. Otherwise this might counteract any libraries you are using which might have deliberately set the system property because they rely on its behavior.

## R8 / ProGuard
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that specific to this header? Because for the others GitHub UI seems to ignore the <a> when deriving the default anchor name (or it only seems to prepend a -).

If possible I think a stable anchor with <a> would be better.

README.md Outdated
@@ -68,6 +68,10 @@ see [`GsonBuilder.disableJdkUnsafe()`](https://javadoc.io/doc/com.google.code.gs

Older Gson versions may also support lower API levels, however this has not been verified.

### R8 / ProGuard

See the details in the related section in [Troubleshooting guide](Troubleshooting.md#r8--proguard).
Copy link
Collaborator
@Marcono1234 Marcono1234 Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See the details in the related section in [Troubleshooting guide](Troubleshooting.md#r8--proguard).
See the details in the related section in the [Troubleshooting guide](Troubleshooting.md#r8--proguard).

Maybe it would also be better to remove this (but still as dedicated "R8 / ProGuard" section) below the "Documentation" section, since it is more specific documentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I document the R8 / ProGuard section explicitly as I want to warn users like https://github.com/square/retrofit?tab=readme-ov-file#r8--proguard and OkHttp did.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is fine and a good thing. I was just wondering whether it would be better to have the (existing) "Documentation" section first in the README:

...

Documentation

  • API Javadoc: Documentation for the current release
  • ...

ProGuard / R8

See the details in the related ...

Because this is a more specific aspect of the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasonable! 495aa1b

@@ -67,15 +68,17 @@ Or in case this occurs for a field in one of your classes which you did not actu

**Reason:** You probably have not configured ProGuard / R8 correctly

**Solution:** Make sure you have configured ProGuard / R8 correctly to preserve the names of your fields. See the [Android example](examples/android-proguard-example/README.md) for more information.
**Solution:** Make sure you have configured ProGuard / R8 correctly to preserve the names of your fields.
See the section below, it's related to this issue.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly link to the section as well?

Suggested change
See the section below, it's related to this issue.
See the [ProGuard / R8](#r8--proguard) section for more information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intended. As I see it, the "random property names" and "field names are being obfuscated" are the same issue; I just wanted to link them together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should merge these 2 sections.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep them separate for now. The symptoms are different (but similar) and if I recall correctly users had experienced and asked about both problems already in the past.

Goooler and others added 5 commits April 13, 2025 20:49
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
@Goooler Goooler force-pushed the remove-android-proguard-example branch from a631002 to 31a02bd Compare April 13, 2025 13:05
@Goooler
Copy link
Contributor Author
Goooler commented Apr 14, 2025

it should only say "no additional ProGuard configuration is needed"

it should document requirements for user classes

This point looks unrelated to this PR.

fields must be annotated with @SerializedName

Yeah, I see this point has been noted times like

If you want to preserve backward compatibility for you app you can use [`@SerializedName`](https://www.javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/annotations/SerializedName.html) on the fields to specify the obfuscated name as alternate, for example: `@SerializedName(value = "myprop", alternate = "a")`

- The name you have specified with a [`@SerializedName`](https://www.javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/annotations/SerializedName.html) annotation for a field collides with the name of another field

Actually, users can keep full the classes as instead, it's not fields must be.

Guardsquare/proguard#337

Good to know this! We can note it. And may invert all ProGuard / R8 stuff to R8 / ProGuard to prefer the R8 side.

Copy link
Collaborator
@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, looks good to me. I might do some small follow-up changes, but thanks for taking up this task in the first place!

Copy link
Member
@eamonnmcmanus eamonnmcmanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this!

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 this pull request may close these issues.

Remove examples/android-proguard-example
3 participants
0