From 4bbc5b2ff80646e1ec5e037e3de430f017b1173f Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Sun, 19 Aug 2018 10:32:00 +0200 Subject: [PATCH 1/3] Embed ProGuard rules in the jar --- README.md | 30 ++++--------------- .../META-INF/proguard/moshi-kotlin.pro | 3 ++ .../resources/META-INF/proguard/moshi.pro | 18 +++++++++++ 3 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 kotlin/reflect/src/main/resources/META-INF/proguard/moshi-kotlin.pro create mode 100644 moshi/src/main/resources/META-INF/proguard/moshi.pro diff --git a/README.md b/README.md index 1c8e47e..7314f1a 100644 --- a/README.md +++ b/README.md @@ -578,34 +578,14 @@ implementation 'com.squareup.moshi:moshi:1.6.0' Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. -ProGuard +R8 / ProGuard -------- -If you are using ProGuard you might need to add the following options: -``` --dontwarn okio.** --dontwarn javax.annotation.** --keepclasseswithmembers class * { - @com.squareup.moshi.* ; -} --keep @com.squareup.moshi.JsonQualifier interface * -``` -Additional rules are needed if you are using Kotlin: +If you are using R8 or ProGuard add the options from [this file](https://github.com/square/moshi/blob/master/moshi/src/main/resources/META-INF/proguard/moshi.pro). -*...If you are using the reflect API (i.e. `KotlinJsonAdapterFactory`):* -``` --keepclassmembers class kotlin.Metadata { - public ; -} -``` -*...If you are using the codegen API (i.e. `JsonClass(generateAdapter = true)`):* -``` --keep class **JsonAdapter { - (...); - ; -} --keepnames @com.squareup.moshi.JsonClass class * -``` +The `moshi-kotlin` artifact additionally requires the options from [this file](https://github.com/square/moshi/blob/master/kotlin/reflect/src/main/resources/META-INF/proguard/moshi-kotlin.pro) + +You might also need rules for Okio which is a dependency of this library. License -------- diff --git a/kotlin/reflect/src/main/resources/META-INF/proguard/moshi-kotlin.pro b/kotlin/reflect/src/main/resources/META-INF/proguard/moshi-kotlin.pro new file mode 100644 index 0000000..a72ffdf --- /dev/null +++ b/kotlin/reflect/src/main/resources/META-INF/proguard/moshi-kotlin.pro @@ -0,0 +1,3 @@ +-keepclassmembers class kotlin.Metadata { + public ; +} diff --git a/moshi/src/main/resources/META-INF/proguard/moshi.pro b/moshi/src/main/resources/META-INF/proguard/moshi.pro new file mode 100644 index 0000000..b2cc812 --- /dev/null +++ b/moshi/src/main/resources/META-INF/proguard/moshi.pro @@ -0,0 +1,18 @@ +# JSR 305 annotations are for embedding nullability information. +-dontwarn javax.annotation.** + +-keepclasseswithmembers class * { + @com.squareup.moshi.* ; +} + +-keep @com.squareup.moshi.JsonQualifier interface * + +# 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 { + (...); + ; +} From 597da2d861eb66424575a9778f6245bb6933aa06 Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Fri, 24 Aug 2018 10:47:22 +0200 Subject: [PATCH 2/3] keep BuiltInsLoaderImpl for kotlin reflect artifact --- .../src/main/resources/META-INF/proguard/moshi-kotlin.pro | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kotlin/reflect/src/main/resources/META-INF/proguard/moshi-kotlin.pro b/kotlin/reflect/src/main/resources/META-INF/proguard/moshi-kotlin.pro index a72ffdf..1565786 100644 --- a/kotlin/reflect/src/main/resources/META-INF/proguard/moshi-kotlin.pro +++ b/kotlin/reflect/src/main/resources/META-INF/proguard/moshi-kotlin.pro @@ -1,3 +1,5 @@ +-keep class kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoaderImpl + -keepclassmembers class kotlin.Metadata { public ; } From 24e0777ebdf49dadc79f3834dd1b55190789cdf1 Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Fri, 7 Sep 2018 08:04:56 +0200 Subject: [PATCH 3/3] add period to comments --- moshi/src/main/resources/META-INF/proguard/moshi.pro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moshi/src/main/resources/META-INF/proguard/moshi.pro b/moshi/src/main/resources/META-INF/proguard/moshi.pro index b2cc812..c639bc7 100644 --- a/moshi/src/main/resources/META-INF/proguard/moshi.pro +++ b/moshi/src/main/resources/META-INF/proguard/moshi.pro @@ -7,10 +7,10 @@ -keep @com.squareup.moshi.JsonQualifier interface * -# The name of @JsonClass types is used to look up the generated adapter +# 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 +# Retain generated JsonAdapters if annotated type is retained. -if @com.squareup.moshi.JsonClass class * -keep class <1>JsonAdapter { (...);