From 532c3d22dcf7d671f7ac40de40584a96a35ed070 Mon Sep 17 00:00:00 2001 From: Justin Boswell Date: Fri, 24 Apr 2020 11:05:38 -0700 Subject: [PATCH] Android now produces an SDK aar, and the samples app now uses that as a dependency. Added maven publishing (#52) --- android/app/build.gradle | 5 +- android/iotdevicesdk/.gitignore | 1 + android/iotdevicesdk/build.gradle | 155 ++++++++++++++++++ android/iotdevicesdk/consumer-rules.pro | 0 android/iotdevicesdk/proguard-rules.pro | 21 +++ .../iotdevicesdk/ExampleInstrumentedTest.java | 27 +++ .../iotdevicesdk/src/main/AndroidManifest.xml | 2 + .../awssdk/iotdevicesdk/ExampleUnitTest.java | 17 ++ android/settings.gradle | 1 + 9 files changed, 226 insertions(+), 3 deletions(-) create mode 100644 android/iotdevicesdk/.gitignore create mode 100644 android/iotdevicesdk/build.gradle create mode 100644 android/iotdevicesdk/consumer-rules.pro create mode 100644 android/iotdevicesdk/proguard-rules.pro create mode 100644 android/iotdevicesdk/src/androidTest/java/software/amazon/awssdk/iotdevicesdk/ExampleInstrumentedTest.java create mode 100644 android/iotdevicesdk/src/main/AndroidManifest.xml create mode 100644 android/iotdevicesdk/src/test/java/software/amazon/awssdk/iotdevicesdk/ExampleUnitTest.java diff --git a/android/app/build.gradle b/android/app/build.gradle index aea53be8d..37f407348 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -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' @@ -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' diff --git a/android/iotdevicesdk/.gitignore b/android/iotdevicesdk/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/android/iotdevicesdk/.gitignore @@ -0,0 +1 @@ +/build diff --git a/android/iotdevicesdk/build.gradle b/android/iotdevicesdk/build.gradle new file mode 100644 index 000000000..f014e3e75 --- /dev/null +++ b/android/iotdevicesdk/build.gradle @@ -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 + } + } + } +} diff --git a/android/iotdevicesdk/consumer-rules.pro b/android/iotdevicesdk/consumer-rules.pro new file mode 100644 index 000000000..e69de29bb diff --git a/android/iotdevicesdk/proguard-rules.pro b/android/iotdevicesdk/proguard-rules.pro new file mode 100644 index 000000000..f1b424510 --- /dev/null +++ b/android/iotdevicesdk/proguard-rules.pro @@ -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 diff --git a/android/iotdevicesdk/src/androidTest/java/software/amazon/awssdk/iotdevicesdk/ExampleInstrumentedTest.java b/android/iotdevicesdk/src/androidTest/java/software/amazon/awssdk/iotdevicesdk/ExampleInstrumentedTest.java new file mode 100644 index 000000000..2d43c00ce --- /dev/null +++ b/android/iotdevicesdk/src/androidTest/java/software/amazon/awssdk/iotdevicesdk/ExampleInstrumentedTest.java @@ -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 Testing documentation + */ +@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()); + } +} diff --git a/android/iotdevicesdk/src/main/AndroidManifest.xml b/android/iotdevicesdk/src/main/AndroidManifest.xml new file mode 100644 index 000000000..2e429e045 --- /dev/null +++ b/android/iotdevicesdk/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/android/iotdevicesdk/src/test/java/software/amazon/awssdk/iotdevicesdk/ExampleUnitTest.java b/android/iotdevicesdk/src/test/java/software/amazon/awssdk/iotdevicesdk/ExampleUnitTest.java new file mode 100644 index 000000000..8107270e1 --- /dev/null +++ b/android/iotdevicesdk/src/test/java/software/amazon/awssdk/iotdevicesdk/ExampleUnitTest.java @@ -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 Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/android/settings.gradle b/android/settings.gradle index c05010163..1041d10c0 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,2 +1,3 @@ rootProject.name='IoTSamples' include ':app' +include ':iotdevicesdk'