Optimize the size of the coroutines library in Android projects (#1282)

* Includes additional R8 rules to disable debugging & stack-trace recovery in optimized
Android builds. Additional savings with AGP 4.0.0-alpha06 (r8-2.0.4-dev) are ~16kb
in uncompressed DEX size.
* Tests are modified to verify that the classes that are supposed to be removed are
indeed removed.
* Cleaner build logic without error-prone "return" in the middle
* Report the size of optimized Android Dex as teamcity metric
diff --git a/build.gradle b/build.gradle
index 273fd00..67e1e27 100644
--- a/build.gradle
+++ b/build.gradle
@@ -138,10 +138,9 @@
     ignoredPackages += "kotlinx.coroutines.internal"
 }
 
-
+// Configure repositories
 allprojects {
-    apply plugin: 'kotlinx-atomicfu' // it also adds all the necessary dependencies
-    def projectName = it.name
+    String projectName = it.name
     repositories {
         /*
          * google should be first in the repository list because some of the play services
@@ -159,30 +158,33 @@
         maven { url "https://kotlin.bintray.com/kotlin-eap" }
         maven { url "https://kotlin.bintray.com/kotlinx" }
     }
+}
 
-    if (projectName == rootModule || projectName == coreModule) return
-
-    // Add dependency to core source sets. Core is configured in kx-core/build.gradle
+// Add dependency to core source sets. Core is configured in kx-core/build.gradle
+configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != coreModule }) {
     evaluationDependsOn(":$coreModule")
-    if (sourceless.contains(projectName)) return
-
     def platform = platformOf(it)
     apply from: rootProject.file("gradle/compile-${platform}.gradle")
-
     dependencies {
         // See comment below for rationale, it will be replaced with "project" dependency
         compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
-
         // the only way IDEA can resolve test classes
         testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
     }
+}
 
+// Configure subprojects with Kotlin sources
+configure(subprojects.findAll { !sourceless.contains(it.name) }) {
+    // Use atomicfu plugin, it also adds all the necessary dependencies
+    apply plugin: 'kotlinx-atomicfu'
+
+    // Configure options for all Kotlin compilation tasks
     tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
         kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
         kotlinOptions.freeCompilerArgs += "-progressive"
         kotlinOptions.freeCompilerArgs += "-XXLanguage:+InlineClasses"
-        // Binary compatibility support
-        kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"]
+        // Remove null assertions to get smaller bytecode on Android
+        kotlinOptions.freeCompilerArgs += ["-Xno-param-assertions", "-Xno-receiver-assertions", "-Xno-call-assertions"]
     }
 }