Skip to content

Commit 582086c

Browse files
authored
Update R8 for Kotlin 1.5.0, enable DEX size metrics back (#2739)
1 parent 537db24 commit 582086c

File tree

2 files changed

+59
-74
lines changed

2 files changed

+59
-74
lines changed

buildSrc/src/main/kotlin/RunR8.kt

-56
This file was deleted.

ui/kotlinx-coroutines-android/build.gradle.kts

+59-18
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies {
1818
testImplementation("org.robolectric:robolectric:${version("robolectric")}")
1919
testImplementation("org.smali:baksmali:${version("baksmali")}")
2020

21-
"r8"("com.android.tools.build:builder:7.0.0-alpha14")
21+
"r8"("com.android.tools.build:builder:7.1.0-alpha01")
2222
}
2323

2424
val optimizedDexDir = File(buildDir, "dex-optim/")
@@ -41,24 +41,65 @@ val runR8NoOptim by tasks.registering(RunR8::class) {
4141
dependsOn("jar")
4242
}
4343

44-
// TODO: Disable the test until we have published version of R8 that supports Kotlin 1.5.0 metadata
45-
46-
//tasks.test {
47-
// // Ensure the R8-processed dex is built and supply its path as a property to the test.
48-
// dependsOn(runR8)
49-
// dependsOn(runR8NoOptim)
50-
//
51-
// inputs.files(optimizedDexFile, unOptimizedDexFile)
52-
//
53-
// systemProperty("dexPath", optimizedDexFile.absolutePath)
54-
// systemProperty("noOptimDexPath", unOptimizedDexFile.absolutePath)
55-
//
56-
// // Output custom metric with the size of the optimized dex
57-
// doLast {
58-
// println("##teamcity[buildStatisticValue key='optimizedDexSize' value='${optimizedDexFile.length()}']")
59-
// }
60-
//}
44+
tasks.test {
45+
// Ensure the R8-processed dex is built and supply its path as a property to the test.
46+
dependsOn(runR8)
47+
dependsOn(runR8NoOptim)
48+
49+
inputs.files(optimizedDexFile, unOptimizedDexFile)
50+
51+
systemProperty("dexPath", optimizedDexFile.absolutePath)
52+
systemProperty("noOptimDexPath", unOptimizedDexFile.absolutePath)
53+
54+
// Output custom metric with the size of the optimized dex
55+
doLast {
56+
println("##teamcity[buildStatisticValue key='optimizedDexSize' value='${optimizedDexFile.length()}']")
57+
}
58+
}
6159

6260
externalDocumentationLink(
6361
url = "https://developer.android.com/reference/"
6462
)
63+
/*
64+
* Task used by our ui/android tests to test minification results and keep track of size of the binary.
65+
*/
66+
open class RunR8 : JavaExec() {
67+
68+
@OutputDirectory
69+
lateinit var outputDex: File
70+
71+
@InputFile
72+
lateinit var inputConfig: File
73+
74+
@InputFile
75+
val inputConfigCommon: File = File("testdata/r8-test-common.pro")
76+
77+
@InputFiles
78+
val jarFile: File = project.tasks.named<Zip>("jar").get().archivePath
79+
80+
init {
81+
classpath = project.configurations["r8"]
82+
main = "com.android.tools.r8.R8"
83+
}
84+
85+
override fun exec() {
86+
// Resolve classpath only during execution
87+
val arguments = mutableListOf(
88+
"--release",
89+
"--no-desugaring",
90+
"--min-api", "26",
91+
"--output", outputDex.absolutePath,
92+
"--pg-conf", inputConfig.absolutePath
93+
)
94+
arguments.addAll(project.configurations["runtimeClasspath"].files.map { it.absolutePath })
95+
arguments.add(jarFile.absolutePath)
96+
97+
args = arguments
98+
99+
project.delete(outputDex)
100+
outputDex.mkdirs()
101+
102+
super.exec()
103+
}
104+
}
105+

0 commit comments

Comments
 (0)