kotlinx.coroutines
kotlinx.coroutines copied to clipboard
[Performance impacting] Upgrade Android Build rules to use standard android library Gradle plugin
The current android build rules relies on a Google Android maven artifact which has not been updated in ~8 years. This is very deprecated as described here
Due to this very old Android version, coroutines cannot access newer Android APIs directly like Handler.createAsync. These methods are still used in coroutines today, but require expensive reflection to access. This impacts startup performance for all coroutines users on Android.
Ideally moving to standard android library Gradle plugin can be done to allow access to newer Android APIs.
I've looked into the issue, and solving this doesn't seem straightforward.
- Android artifacts newer than the version we use seemingly require the Android Gradle plugin.
- The Android Gradle plugin interacts with the Kotlin plugin, and the Kotlin plugin requires the Android plugin to be at least 7.3.1. That's a jump of three major versions! The effect is hard to predict, and we'd need to manually check the published artifacts after the migration.
- The Kotlin plugin for Android is separate from the Kotlin plugin for the JVM. I don't know why that is.
- Our existing build scripts that expect to see either the
kotlin-jvmorkotlin-multiplatformplugin start failing whenkotlin-androidis introduced, and fixing it is not purely syntactic manipulation and requires research. For example,kotlin.target.compilationsis empty forKotlinAndroidExtensionfor some reason. After changing this, we'd also probably need to verify that unrelated modules didn't break in the process.
Basically, it looks like this migration can't be performed without diving deep, learning about the interactions between Android and Kotlin plugins, performing a set of non-trivial changes, and carefully analyzing the potential impact.
You can switch to using https://search.maven.org/artifact/org.robolectric/android-all as your compileOnly dependency for the Android APIs as an easy fix for gaining access to newer APIs.