-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ProGuard default shrinking rules (#2448)
* Update ProGuard default shrinking rules to correctly deal with classes without a no-args constructor * Update test after changing default shrinking rules * Adjust shrinker tests * Update rules * Addressed review comments * Addressed more review comments * Addressed more review comments --------- Co-authored-by: Marcono1234 <[email protected]>
- Loading branch information
1 parent
1e7625b
commit 7b5629b
Showing
9 changed files
with
129 additions
and
78 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
### Common rules for ProGuard and R8 | ||
### Should only contains rules needed specifically for the integration test; | ||
### any general rules which are relevant for all users should not be here but in `META-INF/proguard` of Gson | ||
|
||
-allowaccessmodification | ||
|
||
# On Windows mixed case class names might cause problems | ||
-dontusemixedcaseclassnames | ||
|
||
# Ignore notes about duplicate JDK classes | ||
-dontnote module-info,jdk.internal.** | ||
|
||
|
||
# Keep test entrypoints | ||
-keep class com.example.Main { | ||
public static void runTests(...); | ||
} | ||
-keep class com.example.NoSerializedNameMain { | ||
public static java.lang.String runTest(); | ||
public static java.lang.String runTestNoJdkUnsafe(); | ||
public static java.lang.String runTestNoDefaultConstructor(); | ||
} | ||
|
||
|
||
### Test data setup | ||
|
||
# Keep fields without annotations which should be preserved | ||
-keepclassmembers class com.example.ClassWithNamedFields { | ||
!transient <fields>; | ||
} | ||
|
||
-keepclassmembernames class com.example.ClassWithExposeAnnotation { | ||
<fields>; | ||
} | ||
-keepclassmembernames class com.example.ClassWithJsonAdapterAnnotation { | ||
** f; | ||
} | ||
-keepclassmembernames class com.example.ClassWithVersionAnnotations { | ||
<fields>; | ||
} |
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 |
---|---|---|
@@ -1,48 +1,17 @@ | ||
### Common rules for ProGuard and R8 | ||
### Should only contains rules needed specifically for the integration test; | ||
### any general rules which are relevant for all users should not be here but in `META-INF/proguard` of Gson | ||
# Include common rules | ||
-include common.pro | ||
|
||
-allowaccessmodification | ||
### ProGuard specific rules | ||
|
||
# On Windows mixed case class names might cause problems | ||
-dontusemixedcaseclassnames | ||
|
||
# Ignore notes about duplicate JDK classes | ||
-dontnote module-info,jdk.internal.** | ||
|
||
|
||
# Keep test entrypoints | ||
-keep class com.example.Main { | ||
public static void runTests(...); | ||
} | ||
-keep class com.example.DefaultConstructorMain { | ||
public static java.lang.String runTest(); | ||
public static java.lang.String runTestNoJdkUnsafe(); | ||
public static java.lang.String runTestNoDefaultConstructor(); | ||
} | ||
|
||
|
||
### Test data setup | ||
|
||
# Keep fields without annotations which should be preserved | ||
-keepclassmembers class com.example.ClassWithNamedFields { | ||
!transient <fields>; | ||
} | ||
|
||
-keepclassmembernames class com.example.ClassWithExposeAnnotation { | ||
# Unlike R8, ProGuard does not perform aggressive optimization which makes classes abstract, | ||
# therefore for ProGuard can successfully perform deserialization, and for that need to | ||
# preserve the field names | ||
-keepclassmembernames class com.example.NoSerializedNameMain$TestClass { | ||
<fields>; | ||
} | ||
-keepclassmembernames class com.example.ClassWithJsonAdapterAnnotation { | ||
** f; | ||
} | ||
-keepclassmembernames class com.example.ClassWithVersionAnnotations { | ||
<fields>; | ||
} | ||
|
||
|
||
-keepclassmembernames class com.example.DefaultConstructorMain$TestClass { | ||
-keepclassmembernames class com.example.NoSerializedNameMain$TestClassNotAbstract { | ||
<fields>; | ||
} | ||
-keepclassmembernames class com.example.DefaultConstructorMain$TestClassNotAbstract { | ||
-keepclassmembernames class com.example.NoSerializedNameMain$TestClassWithoutDefaultConstructor { | ||
<fields>; | ||
} |
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
17 changes: 17 additions & 0 deletions
17
shrinker-test/src/main/java/com/example/ClassWithoutDefaultConstructor.java
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,17 @@ | ||
package com.example; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** | ||
* Class without no-args default constructor, but with field annotated with | ||
* {@link SerializedName}. | ||
*/ | ||
public class ClassWithoutDefaultConstructor { | ||
@SerializedName("myField") | ||
public int i; | ||
|
||
// Specify explicit constructor with args to remove implicit no-args default constructor | ||
public ClassWithoutDefaultConstructor(int i) { | ||
this.i = i; | ||
} | ||
} |
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