1 /*
2 * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
5 import kotlinx.kover.api.*
6
<lambda>null7 configurations {
8 create("r8")
9 }
10
<lambda>null11 repositories {
12 mavenCentral()
13 }
14
15 project.configureAar()
16
<lambda>null17 dependencies {
18 configureAarUnpacking()
19
20 compileOnly("com.google.android:android:${version("android")}")
21 compileOnly("androidx.annotation:annotation:${version("androidx_annotation")}")
22
23 testImplementation("com.google.android:android:${version("android")}")
24 testImplementation("org.robolectric:robolectric:${version("robolectric")}")
25 // Required by robolectric
26 testImplementation("androidx.test:core:1.2.0")
27 testImplementation("androidx.test:monitor:1.2.0")
28
29
30 testImplementation("org.smali:baksmali:${version("baksmali")}")
31 "r8"("com.android.tools.build:builder:7.1.0-alpha01")
32 }
33
34 val optimizedDexDir = File(buildDir, "dex-optim/")
35 val unOptimizedDexDir = File(buildDir, "dex-unoptim/")
36
37 val optimizedDexFile = File(optimizedDexDir, "classes.dex")
38 val unOptimizedDexFile = File(unOptimizedDexDir, "classes.dex")
39
<lambda>null40 val runR8 by tasks.registering(RunR8::class) {
41 outputDex = optimizedDexDir
42 inputConfig = file("testdata/r8-test-rules.pro")
43
44 dependsOn("jar")
45 }
46
<lambda>null47 val runR8NoOptim by tasks.registering(RunR8::class) {
48 outputDex = unOptimizedDexDir
49 inputConfig = file("testdata/r8-test-rules-no-optim.pro")
50
51 dependsOn("jar")
52 }
53
<lambda>null54 tasks.test {
55 // Ensure the R8-processed dex is built and supply its path as a property to the test.
56 dependsOn(runR8)
57 dependsOn(runR8NoOptim)
58
59 inputs.files(optimizedDexFile, unOptimizedDexFile)
60
61 systemProperty("dexPath", optimizedDexFile.absolutePath)
62 systemProperty("noOptimDexPath", unOptimizedDexFile.absolutePath)
63
64 // Output custom metric with the size of the optimized dex
65 doLast {
66 println("##teamcity[buildStatisticValue key='optimizedDexSize' value='${optimizedDexFile.length()}']")
67 }
68 }
69
70 externalDocumentationLink(
71 url = "https://developer.android.com/reference/"
72 )
73 /*
74 * Task used by our ui/android tests to test minification results and keep track of size of the binary.
75 */
76 open class RunR8 : JavaExec() {
77
78 @OutputDirectory
79 lateinit var outputDex: File
80
81 @InputFile
82 lateinit var inputConfig: File
83
84 @InputFile
85 val inputConfigCommon: File = File("testdata/r8-test-common.pro")
86
87 @InputFiles
88 val jarFile: File = project.tasks.named<Zip>("jar").get().archivePath
89
90 init {
91 classpath = project.configurations["r8"]
92 main = "com.android.tools.r8.R8"
93 }
94
execnull95 override fun exec() {
96 // Resolve classpath only during execution
97 val arguments = mutableListOf(
98 "--release",
99 "--no-desugaring",
100 "--min-api", "26",
101 "--output", outputDex.absolutePath,
102 "--pg-conf", inputConfig.absolutePath
103 )
104 arguments.addAll(project.configurations["runtimeClasspath"].files.map { it.absolutePath })
105 arguments.add(jarFile.absolutePath)
106
107 args = arguments
108
109 project.delete(outputDex)
110 outputDex.mkdirs()
111
112 super.exec()
113 }
114 }
115
<lambda>null116 tasks.withType<Test> {
117 extensions.configure<KoverTaskExtension> {
118 excludes = excludes + listOf("com.android.*", "android.*") // Exclude robolectric-generated classes
119 }
120 }
121