Skip to content

Commit

Permalink
Update R8 for Kotlin 1.5.0, enable DEX size metrics back (#2739)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad committed Jun 4, 2021
1 parent 537db24 commit 582086c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 74 deletions.
56 changes: 0 additions & 56 deletions buildSrc/src/main/kotlin/RunR8.kt

This file was deleted.

77 changes: 59 additions & 18 deletions ui/kotlinx-coroutines-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
testImplementation("org.robolectric:robolectric:${version("robolectric")}")
testImplementation("org.smali:baksmali:${version("baksmali")}")

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

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

// TODO: Disable the test until we have published version of R8 that supports Kotlin 1.5.0 metadata

//tasks.test {
// // Ensure the R8-processed dex is built and supply its path as a property to the test.
// dependsOn(runR8)
// dependsOn(runR8NoOptim)
//
// inputs.files(optimizedDexFile, unOptimizedDexFile)
//
// systemProperty("dexPath", optimizedDexFile.absolutePath)
// systemProperty("noOptimDexPath", unOptimizedDexFile.absolutePath)
//
// // Output custom metric with the size of the optimized dex
// doLast {
// println("##teamcity[buildStatisticValue key='optimizedDexSize' value='${optimizedDexFile.length()}']")
// }
//}
tasks.test {
// Ensure the R8-processed dex is built and supply its path as a property to the test.
dependsOn(runR8)
dependsOn(runR8NoOptim)

inputs.files(optimizedDexFile, unOptimizedDexFile)

systemProperty("dexPath", optimizedDexFile.absolutePath)
systemProperty("noOptimDexPath", unOptimizedDexFile.absolutePath)

// Output custom metric with the size of the optimized dex
doLast {
println("##teamcity[buildStatisticValue key='optimizedDexSize' value='${optimizedDexFile.length()}']")
}
}

externalDocumentationLink(
url = "https://developer.android.com/reference/"
)
/*
* Task used by our ui/android tests to test minification results and keep track of size of the binary.
*/
open class RunR8 : JavaExec() {

@OutputDirectory
lateinit var outputDex: File

@InputFile
lateinit var inputConfig: File

@InputFile
val inputConfigCommon: File = File("testdata/r8-test-common.pro")

@InputFiles
val jarFile: File = project.tasks.named<Zip>("jar").get().archivePath

init {
classpath = project.configurations["r8"]
main = "com.android.tools.r8.R8"
}

override fun exec() {
// Resolve classpath only during execution
val arguments = mutableListOf(
"--release",
"--no-desugaring",
"--min-api", "26",
"--output", outputDex.absolutePath,
"--pg-conf", inputConfig.absolutePath
)
arguments.addAll(project.configurations["runtimeClasspath"].files.map { it.absolutePath })
arguments.add(jarFile.absolutePath)

args = arguments

project.delete(outputDex)
outputDex.mkdirs()

super.exec()
}
}

0 comments on commit 582086c

Please sign in to comment.