Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 3 | */ |
| 4 | |
Roman Elizarov | 9af2571 | 2018-02-02 09:42:35 +0100 | [diff] [blame] | 5 | repositories { |
| 6 | google() |
Wojtek Kaliciński | d6b0b0f | 2019-06-28 11:41:29 +0200 | [diff] [blame] | 7 | // 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 | |
| 16 | configurations { |
| 17 | r8 |
Roman Elizarov | 9af2571 | 2018-02-02 09:42:35 +0100 | [diff] [blame] | 18 | } |
| 19 | |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 20 | dependencies { |
Roman Elizarov | d1f50a3 | 2017-11-09 12:09:06 +0300 | [diff] [blame] | 21 | compileOnly 'com.google.android:android:4.1.1.4' |
Roman Elizarov | 9af2571 | 2018-02-02 09:42:35 +0100 | [diff] [blame] | 22 | compileOnly 'com.android.support:support-annotations:26.1.0' |
Jake Wharton | 8adbb70 | 2018-09-17 14:35:47 -0400 | [diff] [blame] | 23 | |
| 24 | testImplementation 'com.google.android:android:4.1.1.4' |
| 25 | testImplementation 'org.robolectric:robolectric:4.0-alpha-3' |
Wojtek Kaliciński | d6b0b0f | 2019-06-28 11:41:29 +0200 | [diff] [blame] | 26 | 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 | |
| 32 | class 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 | |
| 76 | def optimizedDex = new File(buildDir, "dex-optim/") |
| 77 | def unOptimizedDex = new File(buildDir, "dex-unoptim/") |
| 78 | |
| 79 | task runR8(type: RunR8Task, dependsOn: 'jar'){ |
| 80 | outputDex = optimizedDex |
| 81 | inputConfig = file('r8-test-rules.pro') |
| 82 | } |
| 83 | |
| 84 | task runR8NoOptim(type: RunR8Task, dependsOn: 'jar'){ |
| 85 | outputDex = unOptimizedDex |
| 86 | inputConfig = file('r8-test-rules-no-optim.pro') |
| 87 | } |
| 88 | |
| 89 | test { |
| 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 Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 100 | } |
Roman Elizarov | e00f0ba | 2017-12-23 00:29:29 +0300 | [diff] [blame] | 101 | |
| 102 | tasks.withType(dokka.getClass()) { |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 103 | externalDocumentationLink { |
| 104 | url = new URL("https://developer.android.com/reference/") |
Vsevolod Tolstopyatov | 71fa64f | 2019-05-15 16:40:27 +0300 | [diff] [blame] | 105 | packageListUrl = projectDir.toPath().resolve("package.list").toUri().toURL() |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 106 | } |
| 107 | } |