From 4bbc5b2ff80646e1ec5e037e3de430f017b1173f Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Sun, 19 Aug 2018 10:32:00 +0200 Subject: [PATCH] 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 { + (...); + ; +}