1buildscript { 2 repositories { 3 jcenter() 4 } 5 dependencies { 6 classpath libraries.android_tools 7 } 8} 9 10description = 'Conscrypt: Android Benchmarks' 11 12ext { 13 androidHome = "$System.env.ANDROID_HOME" 14 androidSdkInstalled = file("$androidHome").exists() 15 androidVersionCode = 1 16 androidVersionName = "$version" 17 androidMinSdkVersion = 24 18 androidTargetSdkVersion = 25 19 androidBuildToolsVersion = "25.0.0" 20 androidBuildToolsDir = "${androidHome}/build-tools/${androidBuildToolsVersion}" 21} 22 23if (androidSdkInstalled) { 24 apply plugin: 'com.android.library' 25 26 android { 27 compileSdkVersion androidTargetSdkVersion 28 buildToolsVersion androidBuildToolsVersion 29 30 compileOptions { 31 sourceCompatibility androidMinJavaVersion; 32 targetCompatibility androidMinJavaVersion 33 } 34 35 defaultConfig { 36 minSdkVersion androidMinSdkVersion 37 targetSdkVersion androidTargetSdkVersion 38 versionCode androidVersionCode 39 versionName androidVersionName 40 } 41 lintOptions { 42 // Some Caliper classes reference packages that don't exist on Android 43 disable 'InvalidPackage' 44 } 45 sourceSets.main { 46 java { 47 srcDirs = [ 48 "src/main/java" 49 ] 50 } 51 } 52 } 53 54 dependencies { 55 compile project(':conscrypt-android'), 56 project(':conscrypt-benchmark-base'), 57 project(':conscrypt-testing') 58 59 compile 'com.google.caliper:caliper:1.0-beta-2' 60 compile libraries.bouncycastle_provider 61 62 } 63 64 // This task bundles up everything we're going to send to the device into a single jar. 65 // We need to include all the Conscrypt code plus the Bouncy Castle jar because the platform 66 // version of Bouncy Castle is jarjared. 67 task depsJar(type: Jar, dependsOn: 'assembleRelease') { 68 archiveName = 'bundled-deps.jar' 69 from { 70 configurations.compile.filter { 71 // Find the jars from our project plus BC 72 it.name.endsWith(".jar") && (it.path.startsWith("${rootDir}") || it.path.contains('org.bouncycastle')) 73 }.collect { 74 zipTree(it) 75 } 76 } 77 from { 78 // Also include the classes.jar from our Android libraries 79 ['.', "${rootDir}/android"].collect { 80 zipTree(it + '/build/intermediates/bundles/default/classes.jar') 81 } 82 } 83 // Bouncy Castle signs their jar, which causes our combined jar to fail to verify. Just 84 // strip out the signature files. 85 exclude "META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA" 86 } 87 88 task runBenchmarks(dependsOn: depsJar) { 89 doLast { 90 // First, determine which ABI the device uses so that we can send the right native lib 91 new ByteArrayOutputStream().withStream { stream -> 92 exec { 93 commandLine = ['adb', 'shell', 'getprop', 'ro.product.cpu.abi'] 94 standardOutput = stream 95 } 96 ext.androidDeviceAbi = stream.toString().trim() 97 ext.androidDevice64Bit = ext.androidDeviceAbi.contains('64') 98 } 99 def nativeLibPath = "/system/lib${androidDevice64Bit ? '64' : ''}/libconscrypt_jni.so" 100 // Send the native library to the device 101 exec { 102 executable "${androidHome}/platform-tools/adb" 103 args 'push' 104 args "${rootDir}/android/build/intermediates/bundles/default/jni/${androidDeviceAbi}/libconscrypt_jni.so" 105 args nativeLibPath 106 } 107 // Execute the benchmarks 108 exec { 109 workingDir "${rootDir}" 110 environment PATH: "${androidBuildToolsDir}:$System.env.PATH" 111 environment JACK_JAR: "${androidBuildToolsDir}/jack.jar" 112 113 executable 'java' 114 args '-cp', 'benchmark-android/vogar.jar', 'vogar.Vogar' 115 args '--classpath', 'benchmark-android/build/libs/bundled-deps.jar' 116 args '--benchmark' 117 args '--language=JN' 118 args '--mode=app_process' 119 args 'org.conscrypt.CaliperAlpnBenchmark' 120 args 'org.conscrypt.CaliperClientSocketBenchmark' 121 args 'org.conscrypt.CaliperEngineHandshakeBenchmark' 122 args 'org.conscrypt.CaliperEngineWrapBenchmark' 123 } 124 // Clean up the native library 125 exec { 126 commandLine = ['adb', 'shell', 'rm', '-f', nativeLibPath] 127 } 128 } 129 } 130} else { 131 logger.warn('Android SDK has not been detected. The Android Benchmark module will not be built.') 132 133 // Disable all tasks 134 tasks.collect { 135 it.enabled = false 136 } 137} 138