-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add ProGuard / R8 integration tests & add default ProGuard rules #2397
Merged
eamonnmcmanus
merged 7 commits into
google:master
from
Marcono1234:marcono1234/r8-proguard-integration-test
May 28, 2023
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1c9f309
Add code shrinking tools integration test
Marcono1234 2ff2a66
Keep no-args constructor of classes usable with JsonAdapter
Marcono1234 1fc9a84
Add library ProGuard rules for Gson
Marcono1234 5c72714
Skip japicmp-maven-plugin for shrinker-test
Marcono1234 99ee4ec
Add more tests for JsonAdapter, add tests for generic classes
Marcono1234 745cf1f
Extend default constructor test
Marcono1234 21eda75
Add Troubleshooting Guide entry for TypeToken
Marcono1234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
### Gson ProGuard and R8 rules which are relevant for all users | ||
### This file is automatically recognized by ProGuard and R8, see https://developer.android.com/build/shrink-code#configuration-files | ||
### | ||
### IMPORTANT: | ||
### - These rules are additive; don't include anything here which is not specific to Gson (such as completely | ||
### disabling obfuscation for all classes); the user would be unable to disable that then | ||
### - These rules are not complete; users will most likely have to add additional rules for their specific | ||
### classes, for example to disable obfuscation for certain fields or to keep no-args constructors | ||
### | ||
|
||
# Keep generic signatures; needed for correct type resolution | ||
-keepattributes Signature | ||
|
||
# Keep Gson annotations | ||
# Note: Cannot perform finer selection here to only cover Gson annotations, see also https://stackoverflow.com/q/47515093 | ||
-keepattributes *Annotation* | ||
|
||
|
||
### The following rules are needed for R8 in "full mode" which only adheres to `-keepattribtues` if | ||
### the corresponding class or field is matches by a `-keep` rule as well, see | ||
### https://r8.googlesource.com/r8/+/refs/heads/master/compatibility-faq.md#r8-full-mode | ||
|
||
# Keep class TypeToken (respectively its generic signature) | ||
-keep class com.google.gson.reflect.TypeToken { *; } | ||
|
||
# Keep any (anonymous) classes extending TypeToken | ||
-keep class * extends com.google.gson.reflect.TypeToken | ||
|
||
# Keep classes with @JsonAdapter annotation | ||
-keep @com.google.gson.annotations.JsonAdapter class * | ||
|
||
# Keep fields with @SerializedName annotation, but allow obfuscation of their names | ||
-keepclassmembers,allowobfuscation class * { | ||
@com.google.gson.annotations.SerializedName <fields>; | ||
} | ||
|
||
# Keep fields with any other Gson annotation | ||
-keepclassmembers class * { | ||
@com.google.gson.annotations.Expose <fields>; | ||
@com.google.gson.annotations.JsonAdapter <fields>; | ||
@com.google.gson.annotations.Since <fields>; | ||
@com.google.gson.annotations.Until <fields>; | ||
} | ||
|
||
# Keep no-args constructor of classes which can be used with @JsonAdapter | ||
# By default their no-args constructor is invoked to create an adapter instance | ||
-keep class * extends com.google.gson.TypeAdapter { | ||
<init>(); | ||
} | ||
-keep class * implements com.google.gson.TypeAdapterFactory { | ||
<init>(); | ||
} | ||
-keep class * implements com.google.gson.JsonSerializer { | ||
<init>(); | ||
} | ||
-keep class * implements com.google.gson.JsonDeserializer { | ||
<init>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# shrinker-test | ||
|
||
This Maven module contains integration tests which check the behavior of Gson when used in combination with code shrinking and obfuscation tools, such as ProGuard or R8. | ||
|
||
The code which is shrunken is under `src/main/java`; it should not contain any important assertions in case the code shrinking tools affect these assertions in any way. The test code under `src/test/java` executes the shrunken and obfuscated JAR and verifies that it behaves as expected. | ||
|
||
**Important:** Because execution of the code shrinking tools is performed during the Maven build, trying to directly run the integration tests from the IDE might not work, or might use stale results if you changed the configuration in between. Run `mvn clean verify` before trying to run the integration tests from the IDE. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this here from the
<dependencyManagement>
because specifying the scope there seems to be discouraged, see https://stackoverflow.com/q/15221299All the modules of this project using JUnit as test dependency already set the scope anyways apparently