Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.ikirincic:aws-sdk-android:release_v2.11.0'
}
dependencies {
implementation("com.github.ikirincic:aws-sdk-android:release_v2.11.0")
}
<dependency>
<groupId>com.github.ikirincic</groupId>
<artifactId>aws-sdk-android</artifactId>
<version>release_v2.11.0</version>
</dependency>
libraryDependencies += "com.github.ikirincic" % "aws-sdk-android" % "release_v2.11.0"
:dependencies [[com.github.ikirincic/aws-sdk-android "release_v2.11.0"]]
The AWS SDK for Android provides a library and documentation for developers to build connected mobile applications using AWS.
Please note the AWS SDK for Android supports Android API level 10+ and newer libraries may require higher API level 21+ and 23+.
The following 3 sections describe how you can depend on the SDK in your application using Gradle with Android Studio, Maven, or by downloading the Jar files from our website. If you use Maven or Gradle you can automatically get new versions of the SDK when they are released.
Simply add to your app's build.gradle (Module)'s dependencies{ } section
dependencies {
implementation 'com.amazonaws:aws-android-sdk-SERVICE:2.x.y'
}
SERVICE can be s3
, ddb
, pinpoint
, etc.
(hint: you can specify 2.+ or 2.x.+ to automatically get the latest version where the + is specified. Remember for version 2.X.Y an increase in X may indicate a breaking change or new features, while increases in Y are likely bug fixes, or small feature improvements)
Note: Cognito Identity authentication abilities are included in the aws-android-sdk-core which all of the following packages depend on.
Here's an example pom.xml showing how you can add Amazon Cognito Identity, Amazon S3, and Amazon Pinpoint to your project:
<dependencies>
<dependency>
<groupid>com.amazonaws</groupid>
<artifactid>aws-android-sdk-core</artifactid>
<version>[2.6,3.0)</version>
</dependency>
<dependency>
<groupid>com.amazonaws</groupid>
<artifactid>aws-android-sdk-s3</artifactid>
<version>[2.6,3.0)</version>
</dependency>
<dependency>
<groupid>com.amazonaws</groupid>
<artifactid>aws-android-sdk-pinpoint</artifactid>
<version>[2.6,3.0)</version>
</dependency>
</dependencies>
You can also download the .zip file containing the jars files of the SDK here. How you include these in your project will depend on the editor you are using.
For an Eclipse project, add the jar files to a folder in your project called 'libs' (create one if it doesn't already exist). The Eclipse Android plug-in will usually add this to your classpath by default. If it does not right click your project --> properties --> Java build path (Libraries tab), add Jar and select the Jars you want to add
For Android studio, in the project view. Add the jars, under YourApp/app/libs, and right click the jar 'Add as Library'
This section explains how to understand and work with the various components of the SDK. The SDK provides direct access to many AWS service API's. It also has a collection higher level API's (called mobile connectors) which make mobile development easier.
Uploading a File to Amazon S3, and then downloading it using Async Task
private class S3Example extends AsyncTask<Void,Void,Void>{
@Override
protected Void doInBackground(Void... params) {
// Initialize the Amazon Cognito credentials provider
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
MY-ACTIVITY.getApplicationContext(), // Application Context
"MY-IDENTITY-POOL-ID", // Identity Pool ID
Regions.SELECT_YOUR_REGION // Region enum
);
AmazonS3Client s3Client = new AmazonS3Client(credentialsProvider);
File fileToUpload = YOUR_FILE;
//(Replace "MY-BUCKET" with your S3 bucket name, and "MY-OBJECT-KEY" with whatever you would like to name the file in S3)
PutObjectRequest putRequest = new PutObjectRequest("MY-BUCKET", "MY-OBJECT-KEY",
fileToUpload);
PutObjectResult putResponse = s3Client.putObject(putRequest);
GetObjectRequest getRequest = new GetObjectRequest("MY-BUCKET", "MY-OBJECT-KEY");
S3Object getResponse = s3Client.getObject(getRequest);
InputStream myObjectBytes = getResponse.getObjectContent();
// Do what you want with the object
myObjectBytes.close();
return null;
}
}
There are only a few fundamentals that are helpful to know when developing against the AWS SDK for Android.
This section describes how you can compile the SDK source code on your own.
For command line approach, you can build the source via Gradle, which can be downloaded and installed from here. After installing Gradle, clone this repository and run
gradlew build
Otherwise, use Android Studio to open the project and build the sub-project(s) of your choice and check the build
folder for libs
or output/aar
.
If you are using a Windows machine, unit tests that involve file deletion can fail because the filesystem does not respond well to file.delete()
.
For more information on Android development, see the Android developer site at: developer.android.com
Visit our GitHub Issues to leave feedback and to connect with other users of the SDK.
Amazon Web Services
See the LICENSE file for more info.