From 482874fdc1f1fe99a81147b90f81102c0c85c58e Mon Sep 17 00:00:00 2001 From: Zac Sweers Date: Tue, 17 Dec 2019 18:35:35 -0500 Subject: [PATCH] Embed proguard/R8 rules in kotlin-reflect artifact jar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Android build pipeline can extract embedded proguard configurations from dependencies and merge them automatically. This adds a conservative proguard configuration to the kotlin-reflect JVM artifact in support of that. This focuses mostly on just retaining what's necessary for kotlin-reflect's own functionality to operate, but could be expanded if community feedback discovers other good candidate rules. With this in place - most Android projects using R8 or Proguard should Just Work™️ with kotlin-reflect. --- .../proguard/kotlin-reflect.pro | 21 +++++++++++++++++ .../r8-from-1.6.0/kotlin-reflect.pro | 16 +++++++++++++ .../r8-upto-1.6.0/kotlin-reflect.pro | 23 +++++++++++++++++++ .../META-INF/proguard/kotlin-reflect.pro | 23 +++++++++++++++++++ libraries/reflect/api/build.gradle | 3 +++ 5 files changed, 86 insertions(+) create mode 100644 core/reflection.jvm/resources/META-INF/com.android.tools/proguard/kotlin-reflect.pro create mode 100644 core/reflection.jvm/resources/META-INF/com.android.tools/r8-from-1.6.0/kotlin-reflect.pro create mode 100644 core/reflection.jvm/resources/META-INF/com.android.tools/r8-upto-1.6.0/kotlin-reflect.pro create mode 100644 core/reflection.jvm/resources/META-INF/proguard/kotlin-reflect.pro diff --git a/core/reflection.jvm/resources/META-INF/com.android.tools/proguard/kotlin-reflect.pro b/core/reflection.jvm/resources/META-INF/com.android.tools/proguard/kotlin-reflect.pro new file mode 100644 index 00000000000..d82eae8518c --- /dev/null +++ b/core/reflection.jvm/resources/META-INF/com.android.tools/proguard/kotlin-reflect.pro @@ -0,0 +1,21 @@ +# When editing this file, update the following files as well: +# - META-INF/com.android.tools/r8-from-1.6.0/kotlin-reflect.pro +# - META-INF/com.android.tools/r8-upto-1.6.0/kotlin-reflect.pro +# - META-INF/proguard/kotlin-reflect.pro +# Keep Metadata annotations so they can be parsed at runtime. +-keep class kotlin.Metadata { *; } + +# Keep implementations of service loaded interfaces +-keep interface kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader +-keep class * implements kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader { public protected *; } +-keep interface kotlin.reflect.jvm.internal.impl.resolve.ExternalOverridabilityCondition +-keep class * implements kotlin.reflect.jvm.internal.impl.resolve.ExternalOverridabilityCondition { public protected *; } + +# Keep generic signatures and annotations at runtime. +-keepattributes Signature,RuntimeVisible*Annotations + +# Don't note on API calls from different JVM versions as they're gated properly at runtime. +-dontnote kotlin.internal.PlatformImplementationsKt + +# Don't note on internal APIs, as there is some class relocating that shrinkers may unnecessarily find suspicious. +-dontwarn kotlin.reflect.jvm.internal.** \ No newline at end of file diff --git a/core/reflection.jvm/resources/META-INF/com.android.tools/r8-from-1.6.0/kotlin-reflect.pro b/core/reflection.jvm/resources/META-INF/com.android.tools/r8-from-1.6.0/kotlin-reflect.pro new file mode 100644 index 00000000000..1958c717df6 --- /dev/null +++ b/core/reflection.jvm/resources/META-INF/com.android.tools/r8-from-1.6.0/kotlin-reflect.pro @@ -0,0 +1,16 @@ +# When editing this file, update the following files as well: +# - META-INF/com.android.tools/proguard/kotlin-reflect.pro +# - META-INF/com.android.tools/r8-upto-1.6.0/kotlin-reflect.pro +# - META-INF/proguard/kotlin-reflect.pro +# Keep Metadata annotations so they can be parsed at runtime. +-keep class kotlin.Metadata { *; } + +# Keep generic signatures and annotations at runtime. +# R8 requires InnerClasses and EnclosingMethod if you keepattributes Signature. +-keepattributes InnerClasses,Signature,RuntimeVisible*Annotations,EnclosingMethod + +# Don't note on API calls from different JVM versions as they're gated properly at runtime. +-dontnote kotlin.internal.PlatformImplementationsKt + +# Don't note on internal APIs, as there is some class relocating that shrinkers may unnecessarily find suspicious. +-dontwarn kotlin.reflect.jvm.internal.** \ No newline at end of file diff --git a/core/reflection.jvm/resources/META-INF/com.android.tools/r8-upto-1.6.0/kotlin-reflect.pro b/core/reflection.jvm/resources/META-INF/com.android.tools/r8-upto-1.6.0/kotlin-reflect.pro new file mode 100644 index 00000000000..ff4886b5b5c --- /dev/null +++ b/core/reflection.jvm/resources/META-INF/com.android.tools/r8-upto-1.6.0/kotlin-reflect.pro @@ -0,0 +1,23 @@ +# When editing this file, update the following files as well: +# - META-INF/com.android.tools/proguard/kotlin-reflect.pro +# - META-INF/com.android.tools/r8-from-1.6.0/kotlin-reflect.pro +# - META-INF/proguard/kotlin-reflect.pro +# Keep Metadata annotations so they can be parsed at runtime. +-keep class kotlin.Metadata { *; } + +# Keep implementations of service loaded interfaces +# R8 will automatically handle these these in 1.6+ +-keep interface kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader +-keep class * implements kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader { public protected *; } +-keep interface kotlin.reflect.jvm.internal.impl.resolve.ExternalOverridabilityCondition +-keep class * implements kotlin.reflect.jvm.internal.impl.resolve.ExternalOverridabilityCondition { public protected *; } + +# Keep generic signatures and annotations at runtime. +# R8 requires InnerClasses and EnclosingMethod if you keepattributes Signature. +-keepattributes InnerClasses,Signature,RuntimeVisible*Annotations,EnclosingMethod + +# Don't note on API calls from different JVM versions as they're gated properly at runtime. +-dontnote kotlin.internal.PlatformImplementationsKt + +# Don't note on internal APIs, as there is some class relocating that shrinkers may unnecessarily find suspicious. +-dontwarn kotlin.reflect.jvm.internal.** \ No newline at end of file diff --git a/core/reflection.jvm/resources/META-INF/proguard/kotlin-reflect.pro b/core/reflection.jvm/resources/META-INF/proguard/kotlin-reflect.pro new file mode 100644 index 00000000000..831b237faac --- /dev/null +++ b/core/reflection.jvm/resources/META-INF/proguard/kotlin-reflect.pro @@ -0,0 +1,23 @@ +# When editing this file, update the following files as well: +# - META-INF/com.android.tools/proguard/kotlin-reflect.pro +# - META-INF/com.android.tools/r8-from-1.6.0/kotlin-reflect.pro +# - META-INF/com.android.tools/r8-upto-1.6.0/kotlin-reflect.pro +# Keep Metadata annotations so they can be parsed at runtime. +-keep class kotlin.Metadata { *; } + +# Keep implementations of service loaded interfaces +# R8 will automatically handle these these in 1.6+ +-keep interface kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader +-keep class * implements kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader { public protected *; } +-keep interface kotlin.reflect.jvm.internal.impl.resolve.ExternalOverridabilityCondition +-keep class * implements kotlin.reflect.jvm.internal.impl.resolve.ExternalOverridabilityCondition { public protected *; } + +# Keep generic signatures and annotations at runtime. +# R8 requires InnerClasses and EnclosingMethod if you keepattributes Signature. +-keepattributes InnerClasses,Signature,RuntimeVisible*Annotations,EnclosingMethod + +# Don't note on API calls from different JVM versions as they're gated properly at runtime. +-dontnote kotlin.internal.PlatformImplementationsKt + +# Don't note on internal APIs, as there is some class relocating that shrinkers may unnecessarily find suspicious. +-dontwarn kotlin.reflect.jvm.internal.** \ No newline at end of file diff --git a/libraries/reflect/api/build.gradle b/libraries/reflect/api/build.gradle index cdaaa1fca8c..f19789fd0c1 100644 --- a/libraries/reflect/api/build.gradle +++ b/libraries/reflect/api/build.gradle @@ -11,6 +11,9 @@ sourceSets { java { srcDir "${rootDir}/core/reflection.jvm/src" } + resources { + srcDir("${rootDir}/core/reflection.jvm/resources") + } } if (includeJava9) {