File tree Expand file tree Collapse file tree 6 files changed +32
-9
lines changed
kotlinx-coroutines-core/jvm/src/internal
ui/kotlinx-coroutines-android Expand file tree Collapse file tree 6 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -165,10 +165,7 @@ threads are handled by Android runtime.
165
165
#### R8 and ProGuard
166
166
167
167
R8 and ProGuard rules are bundled into the [ ` kotlinx-coroutines-android ` ] ( ui/kotlinx-coroutines-android ) module.
168
- For best results it is recommended to use a recent version of R8.
169
- R8 is a replacement for ProGuard in Android ecosystem, it is enabled by default since Android gradle plugin 3.4.0
170
- (3.3.0-beta also had it enabled). The upcoming AGP 4.0.0 has never R8 and additional rules enable
171
- more optimizations, producing smaller binary size.
168
+ For more details see [ "Optimization" section for Android] ( ui/kotlinx-coroutines-android/README.md#optimization ) .
172
169
173
170
### JS
174
171
Original file line number Diff line number Diff line change 8
8
* [ Stacktrace recovery machinery] ( #stacktrace-recovery-machinery )
9
9
* [ Debug agent] ( #debug-agent )
10
10
* [ Debug agent and Android] ( #debug-agent-and-android )
11
+ * [ Android optimization] ( #android-optimization )
11
12
12
13
<!-- - END_TOC -->
13
14
14
-
15
15
## Debugging coroutines
16
+
16
17
Debugging asynchronous programs is challenging, because multiple concurrent coroutines are typically working at the same time.
17
18
To help with that, ` kotlinx.coroutines ` comes with additional features for debugging: debug mode, stacktrace recovery
18
19
and debug agent.
@@ -87,6 +88,14 @@ java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/Mana
87
88
at kotlinx.coroutines.debug.DebugProbes.install(DebugProbes.kt:49)
88
89
-->
89
90
91
+ ## Android optimization
92
+
93
+ In optimized (release) builds with R8 version 1.6.0 or later both
94
+ [ Debugging mode] ( ../../docs/debugging.md#debug-mode ) and
95
+ [ Stacktrace recovery] ( ../../docs/debugging.md#stacktrace-recovery )
96
+ are permanently turned off.
97
+ For more details see [ "Optimization" section for Android] ( ../ui/kotlinx-coroutines-android/README.md#optimization ) .
98
+
90
99
<!-- - MODULE kotlinx-coroutines-core -->
91
100
<!-- - INDEX kotlinx.coroutines -->
92
101
[ DEBUG_PROPERTY_NAME ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-n-a-m-e.html
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ public fun MainCoroutineDispatcher.isMissing(): Boolean = this is MissingMainCor
65
65
66
66
// R8 optimization hook, not const on purpose to enable R8 optimizations via "assumenosideeffects"
67
67
@Suppress(" MayBeConstant" )
68
- val SUPPORT_MISSING = true
68
+ private val SUPPORT_MISSING = true
69
69
70
70
@Suppress(" ConstantConditionIf" )
71
71
private fun createMissingDispatcher (cause : Throwable ? = null, errorHint : String? = null) =
Original file line number Diff line number Diff line change @@ -5,6 +5,23 @@ Provides `Dispatchers.Main` context for Android applications.
5
5
Read [ Guide to UI programming with coroutines] ( https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/coroutines-guide-ui.md )
6
6
for tutorial on this module.
7
7
8
+ # Optimization
9
+
10
+ R8 and ProGuard rules are bundled into this module.
11
+ R8 is a replacement for ProGuard in Android ecosystem, it is enabled by default since Android gradle plugin 3.4.0
12
+ (3.3.0-beta also had it enabled).
13
+ For best results it is recommended to use a recent version of R8, which produces a smaller binary.
14
+
15
+ When optimizations are enabled with R8 version 1.6.0 or later
16
+ the following debugging features are permanently turned off to reduce the size of the resulting binary:
17
+
18
+ * [ Debugging mode] ( ../../docs/debugging.md#debug-mode )
19
+ * [ Stacktrace recovery] ( ../../docs/debugging.md#stacktrace-recovery )
20
+ * The internal assertions in the library are also permanently removed.
21
+
22
+ You can examine the corresponding rules in this
23
+ [ ` coroutines.pro ` ] ( resources/META-INF/com.android.tools/r8-from-1.6.0/coroutines.pro ) file.
24
+
8
25
# Package kotlinx.coroutines.android
9
26
10
27
Provides ` Dispatchers.Main ` context for Android applications.
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ internal class AndroidExceptionPreHandler :
21
21
private fun preHandler (): Method ? {
22
22
val current = _preHandler
23
23
if (current != = this ) return current as Method ?
24
- val declared = try {
24
+ val declared = try {
25
25
Thread ::class .java.getDeclaredMethod(" getUncaughtExceptionPreHandler" ).takeIf {
26
26
Modifier .isPublic(it.modifiers) && Modifier .isStatic(it.modifiers)
27
27
}
Original file line number Diff line number Diff line change 7
7
-checkdiscard class kotlinx.coroutines.DebugKt
8
8
-checkdiscard class kotlinx.coroutines.internal.StackTraceRecoveryKt
9
9
10
- # Real android projects do not keep this class, but somehow it is kept in this test (R& bug)
10
+ # Real android projects do not keep this class, but somehow it is kept in this test (R8 bug)
11
11
# -checkdiscard class kotlinx.coroutines.internal.MissingMainCoroutineDispatcher
12
12
13
- # Should not keep this class, but it is still there (R& bug)
13
+ # Should not keep this class, but it is still there (R8 bug)
14
14
#-checkdiscard class kotlinx.coroutines.CoroutineId
You can’t perform that action at this time.
0 commit comments