From ac1b74b4d6f9582412228311baf1980ee93e0499 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Thu, 21 Apr 2022 11:13:02 -0400 Subject: [PATCH] Remove unnecessary -keep rule for AndroidDispatcherFactory, AndroidExceptionPreHandler R8 supports keeping and/or optimizing classes found in META-INF/services: https://b.corp.google.com/issues/120436373#comment7 The last R8 commit I can find related to ServerLoader is https://r8-review.googlesource.com/53824 (Sept 2020), so I think R8 1.6 still needs the -keep rule, but 3.0+ should not. Fixes: 3111 --- .../META-INF/com.android.tools/proguard/coroutines.pro | 1 + .../META-INF/com.android.tools/r8-from-1.6.0/coroutines.pro | 4 +--- .../META-INF/com.android.tools/r8-upto-1.6.0/coroutines.pro | 4 +--- .../META-INF/com.android.tools/r8-upto-3.0.0/coroutines.pro | 6 ++++++ .../resources/META-INF/proguard/coroutines.pro | 1 + .../src/AndroidExceptionPreHandler.kt | 2 -- 6 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-upto-3.0.0/coroutines.pro diff --git a/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/proguard/coroutines.pro b/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/proguard/coroutines.pro index c7cd15fe11..615d5506af 100644 --- a/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/proguard/coroutines.pro +++ b/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/proguard/coroutines.pro @@ -3,3 +3,4 @@ # - META-INF/proguard/coroutines.pro -keep class kotlinx.coroutines.android.AndroidDispatcherFactory {*;} +-keep class kotlinx.coroutines.android.AndroidExceptionPreHandler {*;} diff --git a/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-from-1.6.0/coroutines.pro b/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-from-1.6.0/coroutines.pro index 0d04990ad9..cf317c41e3 100644 --- a/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-from-1.6.0/coroutines.pro +++ b/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-from-1.6.0/coroutines.pro @@ -9,8 +9,6 @@ boolean ANDROID_DETECTED return true; } --keep class kotlinx.coroutines.android.AndroidDispatcherFactory {*;} - # Disable support for "Missing Main Dispatcher", since we always have Android main dispatcher -assumenosideeffects class kotlinx.coroutines.internal.MainDispatchersKt { boolean SUPPORT_MISSING return false; @@ -21,4 +19,4 @@ boolean getASSERTIONS_ENABLED() return false; boolean getDEBUG() return false; boolean getRECOVER_STACK_TRACES() return false; -} \ No newline at end of file +} diff --git a/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-upto-1.6.0/coroutines.pro b/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-upto-1.6.0/coroutines.pro index 549d0e85a1..2d9240147a 100644 --- a/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-upto-1.6.0/coroutines.pro +++ b/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-upto-1.6.0/coroutines.pro @@ -2,8 +2,6 @@ # - META-INF/com.android.tools/proguard/coroutines.pro # - META-INF/proguard/coroutines.pro --keep class kotlinx.coroutines.android.AndroidDispatcherFactory {*;} - -assumenosideeffects class kotlinx.coroutines.internal.FastServiceLoader { boolean ANDROID_DETECTED return true; -} \ No newline at end of file +} diff --git a/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-upto-3.0.0/coroutines.pro b/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-upto-3.0.0/coroutines.pro new file mode 100644 index 0000000000..0d2d890241 --- /dev/null +++ b/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-upto-3.0.0/coroutines.pro @@ -0,0 +1,6 @@ +# After R8 3.0.0 (or probably sometime before that), R8 learned how to optimize +# classes mentioned in META-INF/services files, and explicitly -keeping them +# disables these optimizations. +# https://github.com/Kotlin/kotlinx.coroutines/issues/3111 +-keep class kotlinx.coroutines.android.AndroidDispatcherFactory {*;} +-keep class kotlinx.coroutines.android.AndroidExceptionPreHandler {*;} diff --git a/ui/kotlinx-coroutines-android/resources/META-INF/proguard/coroutines.pro b/ui/kotlinx-coroutines-android/resources/META-INF/proguard/coroutines.pro index 6c918d49e7..98331e98d6 100644 --- a/ui/kotlinx-coroutines-android/resources/META-INF/proguard/coroutines.pro +++ b/ui/kotlinx-coroutines-android/resources/META-INF/proguard/coroutines.pro @@ -5,3 +5,4 @@ # - META-INF/com.android.tools/r8-upto-1.6.0/coroutines.pro -keep class kotlinx.coroutines.android.AndroidDispatcherFactory {*;} +-keep class kotlinx.coroutines.android.AndroidExceptionPreHandler {*;} diff --git a/ui/kotlinx-coroutines-android/src/AndroidExceptionPreHandler.kt b/ui/kotlinx-coroutines-android/src/AndroidExceptionPreHandler.kt index af32191f53..0bc603ea1e 100644 --- a/ui/kotlinx-coroutines-android/src/AndroidExceptionPreHandler.kt +++ b/ui/kotlinx-coroutines-android/src/AndroidExceptionPreHandler.kt @@ -5,12 +5,10 @@ package kotlinx.coroutines.android import android.os.* -import androidx.annotation.* import kotlinx.coroutines.* import java.lang.reflect.* import kotlin.coroutines.* -@Keep internal class AndroidExceptionPreHandler : AbstractCoroutineContextElement(CoroutineExceptionHandler), CoroutineExceptionHandler {