gson-comments/examples/android-proguard-example
Marcono1234 08174e2019
Perform minor code clean-up (#2544)
* Perform minor code clean-up

Notable changes:
- Replace most usages of `<code>` with `{@code ...}` in Javadoc
- Add proper summary sentence to `GsonBuilder.enableComplexMapKeySerialization`
- Extend documentation for `GsonBuilder.setDateFormat` methods
- Fix `TypeToken.isAssignableFrom(Type)` throwing AssertionError in some cases
  Maybe the method should not throw an exception in the first place, but it
  might not matter much since it is deprecated already anyway.
- Remove outdated `throws NumberFormatException` from internal
  `JsonReader.nextQuotedValue`; the behavior had been changed by
  85ebaf7c35
- Fix incorrect documentation on JsonScope fields
- Fix unit tests having 'expected' and 'actual' switched
- Use dedicated Truth methods instead of `isTrue()` / `isFalse()`
- Use common helper methods in JsonWriterTest to avoid duplication

* Implement `toString()` for ReflectionAccessFilter constants

* Address most of the review comments

* Add comment about `source.scm.tag=HEAD` warning

Actually it looks like the warning is not actually caused by usage of
`HEAD` as value, but rather because the project has a snapshot version
during development (which is expected though), see
https://github.com/apache/maven-artifact-plugin/blob/maven-artifact-plugin-3.5.0/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java#L140

But this is not a problem either since during release a non-snapshot
version is used.
2023-11-19 09:01:19 -08:00
..
res initial cut at an example Android application that uses Proguard with Gson 2011-07-22 20:55:37 +00:00
src/com/google/gson/examples/android Perform minor code clean-up (#2544) 2023-11-19 09:01:19 -08:00
AndroidManifest.xml Removed the executable flag from clearly text files 2018-04-26 10:23:15 +03:00
README.md Adjust ProGuard default rules and shrinking tests (#2420) 2023-07-24 07:34:02 -07:00
default.properties initial cut at an example Android application that uses Proguard with Gson 2011-07-22 20:55:37 +00:00
proguard.cfg Retain generic signature of TypeToken with R8 version 3.0 and higher 2021-08-05 09:18:32 +02:00

README.md

android-proguard-example

Example Android project showing how to properly configure ProGuard. ProGuard is a tool for 'shrinking' and obfuscating compiled classes. It can rename methods and fields, or remove them if they appear to be unused. This can cause issues for Gson which uses Java reflection to access the fields of a class. It is necessary to configure ProGuard to make sure that Gson works correctly.

Also have a look at the ProGuard manual and the ProGuard Gson examples for more details on how ProGuard can be configured.

The R8 code shrinker uses the same rule format as ProGuard, but there are differences between these two tools. Have a look at R8's Compatibility FAQ, and especially at the Gson section.

Note that the latest Gson versions (> 2.10.1) apply some of the rules shown in proguard.cfg automatically by default, see the file gson/META-INF/proguard/gson.pro for the Gson version you are using. In general if your classes are top-level classes or are static, have a no-args constructor and their fields are annotated with Gson's @SerializedName, you might not have to perform any additional ProGuard or R8 configuration.

An alternative to writing custom keep rules for your classes in the ProGuard configuration can be to use Android's @Keep annotation.