blob: 5537577d7e4e48f21d74a5d150dda1a31dd947fa [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
Roman Elizarov9af25712018-02-02 09:42:35 +01005repositories {
6 google()
Wojtek Kalicińskid6b0b0f2019-06-28 11:41:29 +02007 // TODO Remove once R8 is updated to a 1.6.x version.
8 maven {
9 url "http://storage.googleapis.com/r8-releases/raw/master"
10 metadataSources {
11 artifact()
12 }
13 }
14}
15
16configurations {
17 r8
Roman Elizarov9af25712018-02-02 09:42:35 +010018}
19
Kirill Timofeeva5186962017-10-25 14:25:47 +030020dependencies {
Roman Elizarovd1f50a32017-11-09 12:09:06 +030021 compileOnly 'com.google.android:android:4.1.1.4'
Roman Elizarov9af25712018-02-02 09:42:35 +010022 compileOnly 'com.android.support:support-annotations:26.1.0'
Jake Wharton8adbb702018-09-17 14:35:47 -040023
24 testImplementation 'com.google.android:android:4.1.1.4'
25 testImplementation 'org.robolectric:robolectric:4.0-alpha-3'
Wojtek Kalicińskid6b0b0f2019-06-28 11:41:29 +020026 testImplementation 'org.smali:baksmali:2.2.7'
27
28 // TODO Replace with a 1.6.x version once released to maven.google.com.
29 r8 'com.android.tools:r8:a7ce65837bec81c62261bf0adac73d9c09d32af2'
30}
31
32class RunR8Task extends JavaExec {
33
34 @OutputDirectory
35 File outputDex
36
37 @InputFile
38 File inputConfig
39
40 @InputFile
41 final File inputConfigCommon = new File('r8-test-common.pro')
42
43 @InputFiles
44 final File jarFile = project.jar.archivePath
45
46 @Override
47 Task configure(Closure closure) {
48 super.configure(closure)
49 classpath = project.configurations.r8
50 main = 'com.android.tools.r8.R8'
51
52 def arguments = [
53 '--release',
54 '--no-desugaring',
55 '--output', outputDex.absolutePath,
56 '--pg-conf', inputConfig.absolutePath
57 ]
58 arguments.addAll(project.configurations.runtimeClasspath.files.collect { it.absolutePath })
59 arguments.addAll(jarFile.absolutePath)
60
61 args = arguments
62 return this
63 }
64
65 @Override
66 void exec() {
67 if (outputDex.exists()) {
68 outputDex.deleteDir()
69 }
70 outputDex.mkdirs()
71
72 super.exec()
73 }
74}
75
76def optimizedDex = new File(buildDir, "dex-optim/")
77def unOptimizedDex = new File(buildDir, "dex-unoptim/")
78
79task runR8(type: RunR8Task, dependsOn: 'jar'){
80 outputDex = optimizedDex
81 inputConfig = file('r8-test-rules.pro')
82}
83
84task runR8NoOptim(type: RunR8Task, dependsOn: 'jar'){
85 outputDex = unOptimizedDex
86 inputConfig = file('r8-test-rules-no-optim.pro')
87}
88
89test {
90 // Ensure the R8-processed dex is built and supply its path as a property to the test.
91 dependsOn(runR8)
92 dependsOn(runR8NoOptim)
93 def dex1 = new File(optimizedDex, "classes.dex")
94 def dex2 = new File(unOptimizedDex, "classes.dex")
95
96 inputs.files(dex1, dex2)
97
98 systemProperty 'dexPath', dex1.absolutePath
99 systemProperty 'noOptimDexPath', dex2.absolutePath
Kirill Timofeeva5186962017-10-25 14:25:47 +0300100}
Roman Elizarove00f0ba2017-12-23 00:29:29 +0300101
102tasks.withType(dokka.getClass()) {
Kirill Timofeeva5186962017-10-25 14:25:47 +0300103 externalDocumentationLink {
104 url = new URL("https://developer.android.com/reference/")
Vsevolod Tolstopyatov71fa64f2019-05-15 16:40:27 +0300105 packageListUrl = projectDir.toPath().resolve("package.list").toUri().toURL()
Kirill Timofeeva5186962017-10-25 14:25:47 +0300106 }
107}