|
| 1 | +/* |
| 2 | + * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 3 | + */ |
| 4 | + |
| 5 | +import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink |
| 6 | +import org.jetbrains.dokka.gradle.DokkaTask |
| 7 | +import java.net.URL |
| 8 | + |
| 9 | +repositories { |
| 10 | + google() |
| 11 | +} |
| 12 | + |
| 13 | +configurations { |
| 14 | + create("r8") |
| 15 | +} |
| 16 | + |
| 17 | +dependencies { |
| 18 | + compileOnly("com.google.android:android:${version("android")}") |
| 19 | + compileOnly("androidx.annotation:annotation:${version("androidx_annotation")}") |
| 20 | + |
| 21 | + testImplementation("com.google.android:android:${version("android")}") |
| 22 | + testImplementation("org.robolectric:robolectric:${version("robolectric")}") |
| 23 | + testImplementation("org.smali:baksmali:${version("baksmali")}") |
| 24 | + |
| 25 | + "r8"("com.android.tools.build:builder:4.0.0-alpha06") // Contains r8-2.0.4-dev |
| 26 | +} |
| 27 | + |
| 28 | +open class RunR8Task : JavaExec() { |
| 29 | + |
| 30 | + @OutputDirectory |
| 31 | + lateinit var outputDex: File |
| 32 | + |
| 33 | + @InputFile |
| 34 | + lateinit var inputConfig: File |
| 35 | + |
| 36 | + @InputFile |
| 37 | + val inputConfigCommon: File = File("testdata/r8-test-common.pro") |
| 38 | + |
| 39 | + @InputFiles |
| 40 | + val jarFile: File = project.tasks.named<Zip>("jar").get().archivePath |
| 41 | + |
| 42 | + init { |
| 43 | + classpath = project.configurations["r8"] |
| 44 | + main = "com.android.tools.r8.R8" |
| 45 | + } |
| 46 | + |
| 47 | + override fun exec() { |
| 48 | + // Resolve classpath only during execution |
| 49 | + val arguments = mutableListOf( |
| 50 | + "--release", |
| 51 | + "--no-desugaring", |
| 52 | + "--output", outputDex.absolutePath, |
| 53 | + "--pg-conf", inputConfig.absolutePath |
| 54 | + ) |
| 55 | + arguments.addAll(project.configurations.runtimeClasspath.files.map { it.absolutePath }) |
| 56 | + arguments.add(jarFile.absolutePath) |
| 57 | + |
| 58 | + args = arguments |
| 59 | + |
| 60 | + project.delete(outputDex) |
| 61 | + outputDex.mkdirs() |
| 62 | + |
| 63 | + super.exec() |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +val optimizedDexDir = File(buildDir, "dex-optim/") |
| 68 | +val unOptimizedDexDir = File(buildDir, "dex-unoptim/") |
| 69 | + |
| 70 | +val optimizedDexFile = File(optimizedDexDir, "classes.dex") |
| 71 | +val unOptimizedDexFile = File(unOptimizedDexDir, "classes.dex") |
| 72 | + |
| 73 | +val runR8 = tasks.register<RunR8Task>("runR8") { |
| 74 | + outputDex = optimizedDexDir |
| 75 | + inputConfig = file("testdata/r8-test-rules.pro") |
| 76 | + |
| 77 | + dependsOn("jar") |
| 78 | +} |
| 79 | + |
| 80 | +val runR8NoOptim = tasks.register<RunR8Task>("runR8NoOptim") { |
| 81 | + outputDex = unOptimizedDexDir |
| 82 | + inputConfig = file("testdata/r8-test-rules-no-optim.pro") |
| 83 | + |
| 84 | + dependsOn("jar") |
| 85 | +} |
| 86 | + |
| 87 | +tasks.test { |
| 88 | + // Ensure the R8-processed dex is built and supply its path as a property to the test. |
| 89 | + dependsOn(runR8) |
| 90 | + dependsOn(runR8NoOptim) |
| 91 | + |
| 92 | + inputs.files(optimizedDexFile, unOptimizedDexFile) |
| 93 | + |
| 94 | + systemProperty("dexPath", optimizedDexFile.absolutePath) |
| 95 | + systemProperty("noOptimDexPath", unOptimizedDexFile.absolutePath) |
| 96 | + |
| 97 | + // Output custom metric with the size of the optimized dex |
| 98 | + doLast { |
| 99 | + println("##teamcity[buildStatisticValue key='optimizedDexSize' value='${optimizedDexFile.length()}']") |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +tasks.withType<DokkaTask>().configureEach { |
| 104 | + externalDocumentationLink(delegateClosureOf<ExternalDocumentationLink.Builder> { |
| 105 | + url = URL("https://developer.android.com/reference/") |
| 106 | + packageListUrl = projectDir.toPath().resolve("package.list").toUri().toURL() |
| 107 | + }) |
| 108 | +} |
0 commit comments