|
| 1 | +import java.util.regex.Pattern |
| 2 | + |
| 3 | +apply plugin: 'com.android.library' |
| 4 | + |
| 5 | +Properties getGitTag() { |
| 6 | + def gitTag = "git describe --tags".execute().text.trim() |
| 7 | + def version = new Properties() |
| 8 | + def versionPattern = Pattern.compile('v(\\d+).(\\d+).(\\d+)(-(.+))?') |
| 9 | + def matcher = versionPattern.matcher(gitTag) |
| 10 | + if (matcher.matches()) { |
| 11 | + version['major'] = matcher.group(1) |
| 12 | + version['minor'] = matcher.group(2) |
| 13 | + version['patch'] = matcher.group(3) |
| 14 | + try { |
| 15 | + version['tag'] = matcher.group(5) |
| 16 | + } catch (Exception ex) {} |
| 17 | + } |
| 18 | + return version |
| 19 | +} |
| 20 | + |
| 21 | +ext { |
| 22 | + gitVersionName = { |
| 23 | + def version = getGitTag() |
| 24 | + def name = "${version['major']}.${version['minor']}.${version['patch']}" |
| 25 | + return name |
| 26 | + } |
| 27 | + gitVersionCode = { |
| 28 | + def version = getGitTag() |
| 29 | + try { |
| 30 | + def major = version['major'] as int |
| 31 | + def minor = version['minor'] as int |
| 32 | + def patch = version['patch'] as int |
| 33 | + return (major * 1000) + (minor * 100) + patch |
| 34 | + } catch (Exception ex) { |
| 35 | + return 0 |
| 36 | + } |
| 37 | + } |
| 38 | + gitVersionTag = { |
| 39 | + def version = getGitTag() |
| 40 | + return version['tag'] != '' ? '-' + version['tag'] : version['tag'] |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +android { |
| 45 | + compileSdkVersion 29 |
| 46 | + buildToolsVersion "29.0.3" |
| 47 | + |
| 48 | + defaultConfig { |
| 49 | + minSdkVersion 26 |
| 50 | + targetSdkVersion 29 |
| 51 | + versionCode 1 |
| 52 | + versionName "1.0" |
| 53 | + ndkVersion "21.0.6113669" |
| 54 | + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
| 55 | + consumerProguardFiles 'consumer-rules.pro' |
| 56 | + } |
| 57 | + |
| 58 | + sourceSets { |
| 59 | + main { |
| 60 | + java.srcDir '../../sdk/src/main/java' |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + buildTypes { |
| 65 | + debug { |
| 66 | + versionNameSuffix = gitVersionTag() |
| 67 | + } |
| 68 | + release { |
| 69 | + minifyEnabled false |
| 70 | + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 71 | + versionNameSuffix "" |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + compileOptions { |
| 76 | + sourceCompatibility = 1.8 |
| 77 | + targetCompatibility = 1.8 |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +repositories { |
| 82 | + mavenCentral() |
| 83 | + maven { |
| 84 | + url System.getenv('HOME') + "/.m2/repository" |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +dependencies { |
| 89 | + implementation fileTree(dir: 'libs', include: ['*.jar']) |
| 90 | + implementation 'software.amazon.awssdk.crt:android:0.5.4' |
| 91 | + implementation 'com.google.code.gson:gson:2.8.5' |
| 92 | + implementation 'androidx.appcompat:appcompat:1.1.0' |
| 93 | + testImplementation 'junit:junit:4.12' |
| 94 | + androidTestImplementation 'androidx.test.ext:junit:1.1.1' |
| 95 | + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' |
| 96 | +} |
| 97 | + |
| 98 | +// Publishing |
| 99 | +apply plugin: 'maven-publish' |
| 100 | + |
| 101 | +// Sources |
| 102 | +task androidSourcesJar(type: Jar) { |
| 103 | + archiveClassifier.set('sources') |
| 104 | + from android.sourceSets.main.java.srcDirs |
| 105 | +} |
| 106 | + |
| 107 | +// Docs |
| 108 | +task androidDocs(type: Javadoc) { |
| 109 | + source = android.sourceSets.main.java.srcDirs |
| 110 | + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) |
| 111 | + android.libraryVariants.all { variant -> |
| 112 | + if (variant.name == 'release') { |
| 113 | + owner.classpath += variant.javaCompileProvider.get().classpath |
| 114 | + } |
| 115 | + } |
| 116 | + exclude '**/R.html', '**/R.*.html', '**/index.html' |
| 117 | +} |
| 118 | + |
| 119 | +task androidDocsJar(type: Jar) { |
| 120 | + archiveClassifier.set('javadoc') |
| 121 | + from androidDocs.destinationDir |
| 122 | +} |
| 123 | + |
| 124 | +afterEvaluate { |
| 125 | + publishing { |
| 126 | + publications { |
| 127 | + // Creates a Maven publication called "release". |
| 128 | + release(MavenPublication) { |
| 129 | + // Applies the component for the release build variant. |
| 130 | + from components.release |
| 131 | + |
| 132 | + // You can then customize attributes of the publication as shown below. |
| 133 | + groupId = 'software.amazon.awssdk.crt.iotdevicesdk' |
| 134 | + artifactId = 'aws-iot-device-sdk' |
| 135 | + version = android.defaultConfig.versionName |
| 136 | + } |
| 137 | + // Creates a Maven publication called “debug”. |
| 138 | + debug(MavenPublication) { |
| 139 | + // Applies the component for the debug build variant. |
| 140 | + from components.debug |
| 141 | + |
| 142 | + groupId = 'software.amazon.awssdk.crt.iotdevicesdk' |
| 143 | + artifactId = 'aws-iot-device-sdk' |
| 144 | + version = android.defaultConfig.versionName + '-SNAPSHOT' |
| 145 | + } |
| 146 | + } |
| 147 | + repositories { |
| 148 | + maven { |
| 149 | + def snapshotRepo = "https://aws.oss.sonatype.org/content/repositories/snapshots" |
| 150 | + def releaseRepo = "https://aws.oss.sonatype.org/" |
| 151 | + url = version.endsWith('SNAPSHOT') ? snapshotRepo : releaseRepo |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | +} |
0 commit comments