1/* 2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5repositories { 6 google() 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 16configurations { 17 r8 18} 19 20dependencies { 21 compileOnly 'com.google.android:android:4.1.1.4' 22 compileOnly 'com.android.support:support-annotations:26.1.0' 23 24 testImplementation 'com.google.android:android:4.1.1.4' 25 testImplementation 'org.robolectric:robolectric:4.0-alpha-3' 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 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 100} 101 102tasks.withType(dokka.getClass()) { 103 externalDocumentationLink { 104 url = new URL("https://developer.android.com/reference/") 105 packageListUrl = projectDir.toPath().resolve("package.list").toUri().toURL() 106 } 107}