Skip to content

Commit 0eec6f3

Browse files
GooolerMarcono1234
andauthored
Remove outdated android-proguard-example (#2843)
* 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]>
1 parent 4e65e6a commit 0eec6f3

File tree

13 files changed

+19
-333
lines changed

13 files changed

+19
-333
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,3 @@ local.properties
1818
build
1919

2020
.DS_Store
21-
22-
examples/android-proguard-example/gen

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ Older Gson versions may also support lower API levels, however this has not been
7777

7878
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.
7979

80+
### ProGuard / R8
81+
82+
See the details in the related section in the [Troubleshooting guide](Troubleshooting.md#proguard--r8).
83+
8084
### Related Content Created by Third Parties
8185
* [Gson Tutorial](https://www.studytrails.com/java/json/java-google-json-introduction/) by `StudyTrails`
8286
* [Gson Tutorial Series](https://futurestud.io/tutorials/gson-getting-started-with-java-json-serialization-deserialization) by `Future Studio`

Troubleshooting.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ This guide describes how to troubleshoot common issues when using Gson.
2222
The overloads with `Type` parameter do not provide any type-safety guarantees.
2323
- 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.
2424

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.
2627

2728
## <a id="reflection-inaccessible"></a> `InaccessibleObjectException`: 'module ... does not "opens ..." to unnamed module'
2829

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

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

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.
7173

7274
## <a id="android-app-broken-after-app-update"></a> Android app unable to parse JSON after app update
7375

7476
**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
7577

7678
**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
7779

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.
7982

8083
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")`
8184

@@ -346,7 +349,7 @@ For older Gson versions a `RuntimeException` with message 'Missing type paramete
346349
-keep class * extends com.google.gson.reflect.TypeToken
347350
```
348351

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.
350353

351354
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.
352355

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

394397
- 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.
395398
- 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
406+
configuration file.

examples/android-proguard-example/AndroidManifest.xml

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/android-proguard-example/README.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

examples/android-proguard-example/default.properties

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/android-proguard-example/proguard.cfg

Lines changed: 0 additions & 32 deletions
This file was deleted.
Binary file not shown.

examples/android-proguard-example/res/layout/main.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/android-proguard-example/res/values/strings.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/android-proguard-example/src/com/google/gson/examples/android/GsonProguardExampleActivity.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

examples/android-proguard-example/src/com/google/gson/examples/android/model/Cart.java

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)