Skip to content

Commit

Permalink
Android now produces an SDK aar, and the samples app now uses that as…
Browse files Browse the repository at this point in the history
… a dependency. Added maven publishing (#52)
  • Loading branch information
Justin Boswell authored Apr 24, 2020
1 parent e124a1d commit 532c3d2
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 3 deletions.
5 changes: 2 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ android {
applicationId "software.amazon.awssdk.iotsamples"
minSdkVersion 26
targetSdkVersion 29
ndkVersion "21.0.6113669"
versionCode 1
versionName "1.0"
ndkVersion "21.0.6113669"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

sourceSets {
main {
java.srcDir '../../sdk/src/main/java'
java.srcDir '../../samples/BasicPubSub/src/main/java'
java.srcDir '../../samples/Jobs/src/main/java'
java.srcDir '../../samples/PubSubStress/src/main/java'
Expand Down Expand Up @@ -50,8 +49,8 @@ repositories {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":iotdevicesdk")
implementation 'software.amazon.awssdk.crt:android:0.5.4'
implementation 'com.google.code.gson:gson:2.8.5'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core:1.2.0'
Expand Down
1 change: 1 addition & 0 deletions android/iotdevicesdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
155 changes: 155 additions & 0 deletions android/iotdevicesdk/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import java.util.regex.Pattern

apply plugin: 'com.android.library'

Properties getGitTag() {
def gitTag = "git describe --tags".execute().text.trim()
def version = new Properties()
def versionPattern = Pattern.compile('v(\\d+).(\\d+).(\\d+)(-(.+))?')
def matcher = versionPattern.matcher(gitTag)
if (matcher.matches()) {
version['major'] = matcher.group(1)
version['minor'] = matcher.group(2)
version['patch'] = matcher.group(3)
try {
version['tag'] = matcher.group(5)
} catch (Exception ex) {}
}
return version
}

ext {
gitVersionName = {
def version = getGitTag()
def name = "${version['major']}.${version['minor']}.${version['patch']}"
return name
}
gitVersionCode = {
def version = getGitTag()
try {
def major = version['major'] as int
def minor = version['minor'] as int
def patch = version['patch'] as int
return (major * 1000) + (minor * 100) + patch
} catch (Exception ex) {
return 0
}
}
gitVersionTag = {
def version = getGitTag()
return version['tag'] != '' ? '-' + version['tag'] : version['tag']
}
}

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"

defaultConfig {
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
ndkVersion "21.0.6113669"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}

sourceSets {
main {
java.srcDir '../../sdk/src/main/java'
}
}

buildTypes {
debug {
versionNameSuffix = gitVersionTag()
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
versionNameSuffix ""
}
}

compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}

repositories {
mavenCentral()
maven {
url System.getenv('HOME') + "/.m2/repository"
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'software.amazon.awssdk.crt:android:0.5.4'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

// Publishing
apply plugin: 'maven-publish'

// Sources
task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
from android.sourceSets.main.java.srcDirs
}

// Docs
task androidDocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
android.libraryVariants.all { variant ->
if (variant.name == 'release') {
owner.classpath += variant.javaCompileProvider.get().classpath
}
}
exclude '**/R.html', '**/R.*.html', '**/index.html'
}

task androidDocsJar(type: Jar) {
archiveClassifier.set('javadoc')
from androidDocs.destinationDir
}

afterEvaluate {
publishing {
publications {
// Creates a Maven publication called "release".
release(MavenPublication) {
// Applies the component for the release build variant.
from components.release

// You can then customize attributes of the publication as shown below.
groupId = 'software.amazon.awssdk.crt.iotdevicesdk'
artifactId = 'aws-iot-device-sdk'
version = android.defaultConfig.versionName
}
// Creates a Maven publication called “debug”.
debug(MavenPublication) {
// Applies the component for the debug build variant.
from components.debug

groupId = 'software.amazon.awssdk.crt.iotdevicesdk'
artifactId = 'aws-iot-device-sdk'
version = android.defaultConfig.versionName + '-SNAPSHOT'
}
}
repositories {
maven {
def snapshotRepo = "https://aws.oss.sonatype.org/content/repositories/snapshots"
def releaseRepo = "https://aws.oss.sonatype.org/"
url = version.endsWith('SNAPSHOT') ? snapshotRepo : releaseRepo
}
}
}
}
Empty file.
21 changes: 21 additions & 0 deletions android/iotdevicesdk/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package software.amazon.awssdk.iotdevicesdk;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

assertEquals("software.amazon.awssdk.iotdevicesdk.test", appContext.getPackageName());
}
}
2 changes: 2 additions & 0 deletions android/iotdevicesdk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="software.amazon.awssdk.iotdevicesdk" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package software.amazon.awssdk.iotdevicesdk;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
rootProject.name='IoTSamples'
include ':app'
include ':iotdevicesdk'

0 comments on commit 532c3d2

Please sign in to comment.