From c06081b75d10e8a87c36110bed40ecc1f77cf45f Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Fri, 24 May 2019 15:54:08 +0200 Subject: [PATCH] Added more proguard restrictions and rules for kotlin and moshi --- app/build.gradle | 2 +- app/proguard-kotlin.pro | 15 +++++++++++++ app/proguard-moshi.pro | 49 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 app/proguard-kotlin.pro create mode 100644 app/proguard-moshi.pro diff --git a/app/build.gradle b/app/build.gradle index 2bf598cb1..5c423c121 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,7 +28,7 @@ android { buildTypes { release { - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro', 'proguard-moshi.pro', 'proguard-kotlin.pro' } } diff --git a/app/proguard-kotlin.pro b/app/proguard-kotlin.pro new file mode 100644 index 000000000..a59383945 --- /dev/null +++ b/app/proguard-kotlin.pro @@ -0,0 +1,15 @@ +-dontusemixedcaseclassnames +-keep class kotlin.** { *; } +-keep class kotlin.Metadata { *; } +-dontwarn kotlin.** +-keepclassmembers class kotlin.Metadata { + public ; +} + +# Removes runtime null checks - doesn't really matter if it crashes on kotlin or java NPE +-assumenosideeffects class kotlin.jvm.internal.Intrinsics { + static void checkParameterIsNotNull(java.lang.Object, java.lang.String); +} + +# Useless option for dex +-dontpreverify \ No newline at end of file diff --git a/app/proguard-moshi.pro b/app/proguard-moshi.pro new file mode 100644 index 000000000..a5296c3f6 --- /dev/null +++ b/app/proguard-moshi.pro @@ -0,0 +1,49 @@ +# JSR 305 annotations are for embedding nullability information. +-dontwarn javax.annotation.** + +-keepclasseswithmembers class * { + @com.squareup.moshi.* ; +} + +-keep @com.squareup.moshi.JsonQualifier interface * + +# Enum field names are used by the integrated EnumJsonAdapter. +# Annotate enums with @JsonClass(generateAdapter = false) to use them with Moshi. +-keepclassmembers @com.squareup.moshi.JsonClass class * extends java.lang.Enum { + ; +} + +# The name of @JsonClass types is used to look up the generated adapter. +-keepnames @com.squareup.moshi.JsonClass class * + +# Retain generated JsonAdapters if annotated type is retained. +-if @com.squareup.moshi.JsonClass class * +-keep class <1>JsonAdapter { + (...); + ; +} +-if @com.squareup.moshi.JsonClass class **$* +-keep class <1>_<2>JsonAdapter { + (...); + ; +} +-if @com.squareup.moshi.JsonClass class **$*$* +-keep class <1>_<2>_<3>JsonAdapter { + (...); + ; +} +-if @com.squareup.moshi.JsonClass class **$*$*$* +-keep class <1>_<2>_<3>_<4>JsonAdapter { + (...); + ; +} +-if @com.squareup.moshi.JsonClass class **$*$*$*$* +-keep class <1>_<2>_<3>_<4>_<5>JsonAdapter { + (...); + ; +} +-if @com.squareup.moshi.JsonClass class **$*$*$*$*$* +-keep class <1>_<2>_<3>_<4>_<5>_<6>JsonAdapter { + (...); + ; +} \ No newline at end of file