-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from applivery/develop
Develop
- Loading branch information
Showing
3 changed files
with
104 additions
and
1 deletion.
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,102 @@ | ||
-dontwarn org.bouncycastle.jsse.BCSSLParameters | ||
-dontwarn org.bouncycastle.jsse.BCSSLSocket | ||
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider | ||
-dontwarn org.conscrypt.Conscrypt$Version | ||
-dontwarn org.conscrypt.Conscrypt | ||
-dontwarn org.conscrypt.ConscryptHostnameVerifier | ||
-dontwarn org.openjsse.javax.net.ssl.SSLParameters | ||
-dontwarn org.openjsse.javax.net.ssl.SSLSocket | ||
-dontwarn org.openjsse.net.ssl.OpenJSSE | ||
|
||
##---------------Begin: Gson ---------- | ||
|
||
# For using GSON @Expose annotation | ||
-keepattributes *Annotation* | ||
|
||
# Gson specific classes | ||
-dontwarn sun.misc.** | ||
#-keep class com.google.gson.stream.** { *; } | ||
|
||
# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory, | ||
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter) | ||
-keep class * extends com.google.gson.TypeAdapter | ||
-keep public class * implements java.lang.reflect.Type | ||
-keep class * implements com.google.gson.TypeAdapterFactory | ||
-keep class * implements com.google.gson.JsonSerializer | ||
-keep class * implements com.google.gson.JsonDeserializer | ||
|
||
# Prevent R8 from leaving Data object members always null | ||
-keepclasseswithmembers,allowobfuscation,includedescriptorclasses class * { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
@com.google.gson.annotations.SerializedName <fields>; | ||
} | ||
|
||
# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher. | ||
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken | ||
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken | ||
|
||
##---------------End: Gson ---------- | ||
|
||
##---------------Begin: Retrofit 2.X ---------- | ||
# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and | ||
# EnclosingMethod is required to use InnerClasses. | ||
-keepattributes Signature, InnerClasses, EnclosingMethod | ||
|
||
# Retrofit does reflection on method and parameter annotations. | ||
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations | ||
|
||
# Keep annotation default values (e.g., retrofit2.http.Field.encoded). | ||
-keepattributes AnnotationDefault | ||
|
||
# Retain service method parameters when optimizing. | ||
-keepclassmembers,allowshrinking,allowobfuscation interface * { | ||
@retrofit2.http.* <methods>; | ||
} | ||
|
||
# Ignore annotation used for build tooling. | ||
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement | ||
|
||
# Ignore JSR 305 annotations for embedding nullability information. | ||
-dontwarn javax.annotation.** | ||
|
||
# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath. | ||
-dontwarn kotlin.Unit | ||
|
||
# Top-level functions that can only be used by Kotlin. | ||
-dontwarn retrofit2.KotlinExtensions | ||
-dontwarn retrofit2.KotlinExtensions$* | ||
|
||
# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy | ||
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this. | ||
-if interface * { @retrofit2.http.* <methods>; } | ||
-keep,allowobfuscation interface <1> | ||
-if interface * { @retrofit2.http.* public *** *(...); } | ||
-keep,allowoptimization,allowshrinking,allowobfuscation class <3> | ||
|
||
# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items). | ||
-keep,allowobfuscation,allowshrinking interface retrofit2.Call | ||
-keep,allowobfuscation,allowshrinking class retrofit2.Response | ||
-keep,allowobfuscation,allowshrinking class okhttp3.RequestBody | ||
-keep,allowobfuscation,allowshrinking class okhttp3.ResponseBody | ||
|
||
# With R8 full mode generic signatures are stripped for classes that are not | ||
# kept. Suspend functions are wrapped in continuations where the type argument | ||
# is used. | ||
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.** { *; } | ||
##---------------Begin: Retrofit 2.X ---------- | ||
|
||
##---------------Begin: OKHttp ---------- | ||
-keep class okhttp3.** { *; } | ||
-keep interface okhttp3.** { *; } | ||
-dontwarn retrofit2.** | ||
-dontwarn okhttp3.** | ||
|
||
-keepclasseswithmembers class * { | ||
@retrofit2.http.* <methods>; | ||
} | ||
##---------------End: OKHttp ---------- | ||
|
||
##---------------Begin: Okio ---------- | ||
-dontwarn java.nio.file.* | ||
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement | ||
-dontwarn okio.** | ||
##---------------End: Okio ---------- |
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
@imablanco IIRC, this will actually end up keeping a lot of extra code.
I had worked with R8 in the past to create better Gson keep rules that are now embedded directly within Gson:
https://github.com/google/gson/blob/84e5f16acafaa7c55d80a3621a37c7884ca928b6/gson/src/main/resources/META-INF/proguard/gson.pro#L57 (More context).
This generally is enough to ensure that GSON serialized classes are not stripped out by R8.
The issue I initally faced was that the generic here is stripped out by Retrofit.
Retrofit has these proguard keep rules to ensure the generics for their own classes don't get stripped out:
but this will only prevent
ServerResponse
from being stripped out but notServerResponse<T>
here:this should be solvable with just this keep rule:
This didn't work for me due to what I suspect are R8 bugs so I just went with the broader rules here:
this tells R8 not to remove any fields or generics from the network request / response classes. This is conservative in that it will keep more code than is probably necessary, but this is fine for us since we don't ship this code in production and the app size hit even if we did would be negligible (probably <1KB)