Skip to content

Commit e796da2

Browse files
mkj-grampablobaxter
authored andcommitted
R8 specific rules to allow for service loader optimizations (Kotlin#2880)
Fixes the R8 ServiceLoader optimization that broke in the R8 bundled in the new AGP. For details, see https://issuetracker.google.com/issues/196302685
1 parent 7fffa11 commit e796da2

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# When editing this file, update the following files as well:
2+
# - META-INF/proguard/coroutines.pro
3+
# - META-INF/com.android.tools/r8/coroutines.pro
4+
5+
# ServiceLoader support
6+
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
7+
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
8+
9+
# Most of volatile fields are updated with AFU and should not be mangled
10+
-keepclassmembers class kotlinx.coroutines.** {
11+
volatile <fields>;
12+
}
13+
14+
# Same story for the standard library's SafeContinuation that also uses AtomicReferenceFieldUpdater
15+
-keepclassmembers class kotlin.coroutines.SafeContinuation {
16+
volatile <fields>;
17+
}
18+
19+
# These classes are only required by kotlinx.coroutines.debug.AgentPremain, which is only loaded when
20+
# kotlinx-coroutines-core is used as a Java agent, so these are not needed in contexts where ProGuard is used.
21+
-dontwarn java.lang.instrument.ClassFileTransformer
22+
-dontwarn sun.misc.SignalHandler
23+
-dontwarn java.lang.instrument.Instrumentation
24+
-dontwarn sun.misc.Signal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# When editing this file, update the following files as well:
2+
# - META-INF/proguard/coroutines.pro
3+
# - META-INF/com.android.tools/proguard/coroutines.pro
4+
5+
# Most of volatile fields are updated with AFU and should not be mangled
6+
-keepclassmembers class kotlinx.coroutines.** {
7+
volatile <fields>;
8+
}
9+
10+
# Same story for the standard library's SafeContinuation that also uses AtomicReferenceFieldUpdater
11+
-keepclassmembers class kotlin.coroutines.SafeContinuation {
12+
volatile <fields>;
13+
}
14+
15+
# These classes are only required by kotlinx.coroutines.debug.AgentPremain, which is only loaded when
16+
# kotlinx-coroutines-core is used as a Java agent, so these are not needed in contexts where ProGuard is used.
17+
-dontwarn java.lang.instrument.ClassFileTransformer
18+
-dontwarn sun.misc.SignalHandler
19+
-dontwarn java.lang.instrument.Instrumentation
20+
-dontwarn sun.misc.Signal

kotlinx-coroutines-core/jvm/resources/META-INF/proguard/coroutines.pro

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# When editing this file, update the following files as well:
2+
# - META-INF/com.android.tools/proguard/coroutines.pro
3+
# - META-INF/com.android.tools/r8/coroutines.pro
4+
15
# ServiceLoader support
26
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
37
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}

0 commit comments

Comments
 (0)