Set Up Amazon Device Messaging
To use Amazon Device Messaging (ADM) with your app, you first need to include the ADM JAR in your development environment. You can do this either using Android Studio or the command line.
Prerequisites
If you haven't already, see Overview of Amazon Device Messaging for an overview of the ADM architecture. Obtain Credentials describes the process of getting your initial credentials for ADM.
To use ADM in your project, install the following on your development computer:
- The Android SDK (API 15 or higher)
- Any Android SDK system requirements, including the JDK
(These resources are already included when you install Android Studio.)
Adding ADM to Android Studio
To use ADM with your IDE-based project, you add the ADM library to your project as an external JAR. Although you can use ADM with any development environment, this section describes how to add ADM to Android Studio. To add ADM to Android Studio:
- Download the Amazon Device Messaging (ADM) SDK and extract the zip to a convenient location.
- Make sure you have downloaded and installed the current version of Android Studio.
- In Android Studio, create a new Android project or open an existing project.
-
Change the folder structure from Android to Project.
-
Search for the libs folder inside the app folder.
- Copy the amazon-device-messaging-1.1.0.jar file from where you extracted the ADM zip file.
-
Paste the JAR into the libs folder.
-
Right click the JAR file and at end click Add as library.
This automatically adds the
implementation files('libs/amazon-device-messaging-1.1.0.jar')
command to thebuild.gradle
file. -
Finally, because you need the library only at compile time rather than runtime, change the following declaration from
implementation
tocompileOnly
. Change from this:dependencies { implementation files('libs/amazon-device-messaging-1.1.0.jar') }
to that:
dependencies { compileOnly files('libs/amazon-device-messaging-1.1.0.jar') }
Warning: Skipping this step causes runtime errors.
Adding ADM from the command line
Before performing this procedure, update your AndroidManifest.xml file, as described in Integrate Your App. Also ensure that you have Apache ANT installed, with your ANT_HOME
, JAVA_HOME
, and PATH
environmental variables properly defined.
- Change directories into the Android SDK's tools/ path.
-
Run a command with the following syntax, where
<path>
is the location where the project will be created, and<target Android platform>
is the Android platform for which the project is intended. For a list of available platforms, runandroid list targets
.android create project --path <path> --target <target Android platform> --activity ADMActivity --package com.example.amazon.adm
- At the root of your new project, create a new directory, called ext_libs.
- Navigate to the Android/DeviceMessaging/lib directory, in the Amazon Mobile App SDK, and copy the JAR file to your new ext_libs directory.
-
At the root of your new project, create a custom_rules.xml file that contains the following:
<?xml version="1.0" encoding="UTF-8"?> <project name="custom_rules"> <path id="java.compiler.classpath.path"> <fileset dir="ext_libs" includes="*.jar"/> </path> <property name="java.compiler.classpath" refid="java.compiler.classpath.path" /> </project>
-
To build your project, run the following command from the root directory for your project:
ant debug
Make sure that you take similar steps to configure the projects that test your app.
Configuring Proguard
If you use Proguard, edit the proguard-rules.pro
file and add the following configuration:
#This should point to the directory where ADM's JAR is stored
-libraryjars libs
-dontwarn com.amazon.device.messaging.**
-keep class com.amazon.device.messaging.** {*;}
-keep public class * extends com.amazon.device.messaging.ADMMessageReceiver
-keep public class * extends com.amazon.device.messaging.ADMMessageHandlerBase
-keep public class * extends com.amazon.device.messaging.ADMMessageHandlerJobBase
Last updated: Mar 24, 2022