1import java.util.regex.Pattern 2 3apply plugin: 'com.android.library' 4apply plugin: 'signing' 5 6// Before configuring, make sure libcrypto is installed 7preBuild { 8 println('Installing libcrypto prebuilt binaries') 9 def exec = (project.file('fetch_libcrypto.sh').absolutePath).execute() 10 exec.waitForProcessOutput(System.out, System.err) 11} 12 13Properties getGitTag() { 14 def gitTag = "git describe --tags".execute().text.trim() 15 def version = new Properties() 16 def versionPattern = Pattern.compile('v(\\d+).(\\d+).(\\d+)(-(.+))?') 17 def matcher = versionPattern.matcher(gitTag) 18 if (matcher.matches()) { 19 version['major'] = matcher.group(1) 20 version['minor'] = matcher.group(2) 21 version['patch'] = matcher.group(3) 22 try { 23 version['tag'] = matcher.group(5) 24 } catch (Exception ex) {} 25 } 26 return version 27} 28 29ext { 30 gitVersionName = { 31 def version = getGitTag() 32 def name = "${version['major']}.${version['minor']}.${version['patch']}" 33 return name 34 } 35 gitVersionCode = { 36 def version = getGitTag() 37 try { 38 def major = version['major'] as int 39 def minor = version['minor'] as int 40 def patch = version['patch'] as int 41 return (major * 1000) + (minor * 100) + patch 42 } catch (Exception ex) { 43 return 0 44 } 45 } 46 gitVersionTag = { 47 def version = getGitTag() 48 return version['tag'] != '' ? '-' + version['tag'] : version['tag'] 49 } 50} 51 52android { 53 compileSdkVersion 30 54 buildToolsVersion "30.0.3" 55 ndkVersion "21.4.7075529" // LTS version 56 57 useLibrary 'android.test.runner' 58 useLibrary 'android.test.base' 59 useLibrary 'android.test.mock' 60 61 defaultConfig { 62 minSdkVersion 24 // TODO - dictated by CompletableFuture which is API 24+ 63 targetSdkVersion 30 64 versionCode = gitVersionCode() 65 versionName = gitVersionName() 66 67 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 68 69 consumerProguardFiles 'consumer-rules.pro' 70 71 ndk { 72 abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64" 73 } 74 75 externalNativeBuild { 76 cmake { 77 arguments "-DBUILD_DEPS=ON" 78 } 79 } 80 } 81 82 sourceSets { 83 main { 84 java.srcDir '../../src/main/java' 85 java.srcDir 'src/main/java' 86 } 87 androidTest { 88 setRoot '../../src/test' 89 java.srcDir '../../src/test/java' 90 java.srcDir 'src/androidTest/java' 91 assets.srcDir 'src/androidTest/assets' 92 } 93 } 94 95 buildTypes { 96 debug { 97 versionNameSuffix = gitVersionTag() 98 buildConfigField("String", "VERSION_NAME", "\"" + gitVersionName() + "\"") 99 } 100 release { 101 minifyEnabled false 102 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 103 versionNameSuffix "" 104 buildConfigField("String", "VERSION_NAME", "\"" + gitVersionName() + "\"") 105 } 106 } 107 108 externalNativeBuild { 109 cmake { 110 path "../../CMakeLists.txt" 111 buildStagingDirectory "../../target/cmake-build" 112 version "3.10.2" 113 } 114 } 115 116 compileOptions { 117 sourceCompatibility = 1.8 118 targetCompatibility = 1.8 119 // Enable desugaring so that Android lint doesn't flag `java.time` usage. Downstream 120 // consumers will need to enable desugaring to use this library. 121 // See: https://developer.android.com/studio/write/java8-support#library-desugaring 122 coreLibraryDesugaringEnabled true 123 } 124} 125 126build.dependsOn preBuild 127 128dependencies { 129 coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' 130 androidTestImplementation 'org.mockito:mockito-core:3.11.2' 131 androidTestImplementation 'androidx.appcompat:appcompat:1.3.1' 132 androidTestImplementation 'junit:junit:4.13.2' 133 androidTestImplementation 'androidx.test:runner:1.4.0' 134 androidTestImplementation 'androidx.test:monitor:1.4.0@aar' 135 androidTestImplementation 'androidx.test:rules:1.4.0' 136} 137 138// Publishing 139apply plugin: 'maven-publish' 140 141// Sources 142task androidSourcesJar(type: Jar) { 143 archiveClassifier.set('sources') 144 from android.sourceSets.main.java.srcDirs 145} 146 147// Docs 148task androidDocs(type: Javadoc) { 149 source = android.sourceSets.main.java.srcDirs 150 classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 151 android.libraryVariants.all { variant -> 152 if (variant.name == 'release') { 153 owner.classpath += variant.javaCompileProvider.get().classpath 154 } 155 } 156 exclude '**/R.html', '**/R.*.html', '**/index.html' 157} 158 159task androidDocsJar(type: Jar) { 160 archiveClassifier.set('javadoc') 161 from androidDocs.destinationDir 162} 163 164 165afterEvaluate { 166 publishing { 167 repositories { 168 maven { name = "testLocal"; url = "$rootProject.buildDir/m2" } 169 } 170 171 publications { 172 release(MavenPublication) { 173 from components.release 174 175 groupId = 'software.amazon.awssdk.crt' 176 artifactId = 'aws-crt-android' 177 version = project.hasProperty('newVersion') ? project.property('newVersion') : android.defaultConfig.versionName 178 179 pom { 180 name.set("software.amazon.awssdk.crt:aws-crt-android") 181 description.set("Java Android bindings for the AWS SDK Common Runtime") 182 url.set("https://github.com/awslabs/aws-crt-java") 183 licenses { 184 license { 185 name.set("The Apache License, Version 2.0") 186 url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") 187 } 188 } 189 190 developers { 191 developer { 192 id.set("aws-sdk-common-runtime") 193 name.set("AWS SDK Common Runtime Team") 194 email.set("[email protected]") 195 } 196 } 197 198 scm { 199 connection.set("scm:git:git://github.com/awslabs/aws-crt-java.git") 200 developerConnection.set("scm:git:ssh://github.com/awslabs/aws-crt-java.git") 201 url.set("https://github.com/awslabs/aws-crt-java") 202 } 203 } 204 } 205 } 206 207 repositories { 208 maven { 209 def snapshotRepo = "https://aws.oss.sonatype.org/content/repositories/snapshots" 210 def releaseRepo = "https://aws.oss.sonatype.org/" 211 url = version.endsWith('SNAPSHOT') ? snapshotRepo : releaseRepo 212 } 213 } 214 215 if (project.hasProperty("signingKey") && project.hasProperty("signingPassword")) { 216 signing { 217 useInMemoryPgpKeys( 218 (String) project.property("signingKey"), 219 (String) project.property("signingPassword") 220 ) 221 println("key=" + project.property("signingKey")) 222 sign(publications) 223 } 224 } 225 } 226} 227