Skip to content

Commit 532c3d2

Browse files
author
Justin Boswell
authored
Android now produces an SDK aar, and the samples app now uses that as a dependency. Added maven publishing (#52)
1 parent e124a1d commit 532c3d2

File tree

9 files changed

+226
-3
lines changed

9 files changed

+226
-3
lines changed

android/app/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ android {
1010
applicationId "software.amazon.awssdk.iotsamples"
1111
minSdkVersion 26
1212
targetSdkVersion 29
13-
ndkVersion "21.0.6113669"
1413
versionCode 1
1514
versionName "1.0"
15+
ndkVersion "21.0.6113669"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
}
1919

2020
sourceSets {
2121
main {
22-
java.srcDir '../../sdk/src/main/java'
2322
java.srcDir '../../samples/BasicPubSub/src/main/java'
2423
java.srcDir '../../samples/Jobs/src/main/java'
2524
java.srcDir '../../samples/PubSubStress/src/main/java'
@@ -50,8 +49,8 @@ repositories {
5049

5150
dependencies {
5251
implementation fileTree(dir: 'libs', include: ['*.jar'])
52+
implementation project(":iotdevicesdk")
5353
implementation 'software.amazon.awssdk.crt:android:0.5.4'
54-
implementation 'com.google.code.gson:gson:2.8.5'
5554
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
5655
implementation 'androidx.appcompat:appcompat:1.1.0'
5756
implementation 'androidx.core:core:1.2.0'

android/iotdevicesdk/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

android/iotdevicesdk/build.gradle

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
}

android/iotdevicesdk/consumer-rules.pro

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package software.amazon.awssdk.iotdevicesdk;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
25+
assertEquals("software.amazon.awssdk.iotdevicesdk.test", appContext.getPackageName());
26+
}
27+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="software.amazon.awssdk.iotdevicesdk" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package software.amazon.awssdk.iotdevicesdk;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11+
*/
12+
public class ExampleUnitTest {
13+
@Test
14+
public void addition_isCorrect() {
15+
assertEquals(4, 2 + 2);
16+
}
17+
}

android/settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
rootProject.name='IoTSamples'
22
include ':app'
3+
include ':iotdevicesdk'

0 commit comments

Comments
 (0)