You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Remove outdated android-proguard-example
* Apply suggestions from code review
Co-authored-by: Marcono1234 <[email protected]>
* Apply suggestions from code review
Co-authored-by: Marcono1234 <[email protected]>
* Apply suggestions from code review
Co-authored-by: Marcono1234 <[email protected]>
* Fix typos and revert a review change
* Correct the header to align with refs
* Try out the ref id for ProGuard / R8 header
* Revert "Try out the ref id for ProGuard / R8 header"
This reverts commit e8f52fb.
* Rearrange
---------
Co-authored-by: Marcono1234 <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -77,6 +77,10 @@ Older Gson versions may also support lower API levels, however this has not been
77
77
78
78
Please use the ['gson' tag on StackOverflow](https://stackoverflow.com/questions/tagged/gson), [GitHub Discussions](https://github.com/google/gson/discussions) or the [google-gson Google group](https://groups.google.com/group/google-gson) to discuss Gson or to post questions.
79
79
80
+
### ProGuard / R8
81
+
82
+
See the details in the related section in the [Troubleshooting guide](Troubleshooting.md#proguard--r8).
83
+
80
84
### Related Content Created by Third Parties
81
85
*[Gson Tutorial](https://www.studytrails.com/java/json/java-google-json-introduction/) by `StudyTrails`
82
86
*[Gson Tutorial Series](https://futurestud.io/tutorials/gson-getting-started-with-java-json-serialization-deserialization) by `Future Studio`
Copy file name to clipboardExpand all lines: Troubleshooting.md
+15-4Lines changed: 15 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,8 @@ This guide describes how to troubleshoot common issues when using Gson.
22
22
The overloads with `Type` parameter do not provide any type-safety guarantees.
23
23
- When using `TypeToken` make sure you don't capture a type variable. For example avoid something like `new TypeToken<List<T>>()` (where `T` is a type variable). Due to Java [type erasure](https://dev.java/learn/generics/type-erasure/) the actual type of `T` is not available at runtime. Refactor your code to pass around `TypeToken` instances or use [`TypeToken.getParameterized(...)`](https://www.javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/reflect/TypeToken.html#getParameterized(java.lang.reflect.Type,java.lang.reflect.Type...)), for example `TypeToken.getParameterized(List.class, elementType)` where `elementType` is a type you have to provide separately.
24
24
25
-
If you are using a code shrinking tool such as ProGuard or R8 (for example when building an Android app), make sure it is correctly configured to keep generic signatures and to keep Gson's `TypeToken` class. See the [Android example](examples/android-proguard-example/README.md) for more information.
25
+
If you are using a code shrinking tool such as ProGuard / R8 (for example when building an Android app), make sure it is correctly configured to keep generic signatures and to keep Gson's `TypeToken` class.
26
+
See the [ProGuard / R8](#proguard--r8) section for more information.
26
27
27
28
## <aid="reflection-inaccessible"></a> `InaccessibleObjectException`: 'module ... does not "opens ..." to unnamed module'
28
29
@@ -67,15 +68,17 @@ Or in case this occurs for a field in one of your classes which you did not actu
67
68
68
69
**Reason:** You probably have not configured ProGuard / R8 correctly
69
70
70
-
**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.
71
+
**Solution:** Make sure you have configured ProGuard / R8 correctly to preserve the names of your fields.
72
+
See the section below, it's related to this issue.
71
73
72
74
## <aid="android-app-broken-after-app-update"></a> Android app unable to parse JSON after app update
73
75
74
76
**Symptom:** You released a new version of your Android app and it fails to parse JSON data created by the previous version of your app
75
77
76
78
**Reason:** You probably have not configured ProGuard / R8 correctly; probably the field names are being obfuscated and their naming changed between the versions of your app
77
79
78
-
**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.
80
+
**Solution:** Make sure you have configured ProGuard / R8 correctly to preserve the names of your fields.
81
+
See the [ProGuard / R8](#proguard--r8) section for more information.
79
82
80
83
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")`
81
84
@@ -346,7 +349,7 @@ For older Gson versions a `RuntimeException` with message 'Missing type paramete
346
349
-keep class * extends com.google.gson.reflect.TypeToken
347
350
```
348
351
349
-
See also the [Android example](examples/android-proguard-example/README.md) for more information.
352
+
See the [ProGuard / R8](#proguard--r8) section for more information.
350
353
351
354
Note: For newer Gson versions these rules might be applied automatically; make sure you are using the latest Gson version and the latest version of the code shrinking tool.
352
355
@@ -393,3 +396,11 @@ For backward compatibility it is possible to restore Gson's old behavior of allo
393
396
394
397
- 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.
395
398
- 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.
399
+
400
+
## ProGuard / R8
401
+
402
+
If you use Gson as a dependency in an Android project which uses R8 or ProGuard as code shrinking and obfuscation tool you don't have to do anything.
403
+
The specific rules are [already bundled](gson/src/main/resources/META-INF/proguard/gson.pro) (from Gson 2.11.0) into
404
+
the JAR which can be interpreted by R8 automatically. For users who still use older Gson versions, you may need to
405
+
copy the rules from the [`gson.pro`](gson/src/main/resources/META-INF/proguard/gson.pro) file into your own ProGuard
0 commit comments