Grato por sua visita. Neste momento esta página está apenas disponível em inglês.

Get Started with IAP

If you have never worked with the Amazon In-app Purchasing SDK, or have never implemented the IAP API before, this page will help you set up your IDE and familiarize you with the recommended development, testing, and submission workflow for IAP.

For the sake of simplicity, this topic will walk you through importing the IAP sample apps to your IDE, rather than starting a new project from scratch, since most developers prefer to start with a sample. To learn more about how to actually implement the IAP API itself, see Implementing IAP.

The IAP eBook provides a detailed description of the steps required to create an IAP-enabled Android app.

Download the SDK

If you have not already done so, download the Amazon Android SDKs to your computer:

Amazon Android SDK Download (On the SDK download page, click the Android link).

After you extract the files, the IAP SDK files are contained in the folder named AmazonInAppPurchasing.

Set Up Your Development Environment: Android Studio

If you are using Android Studio as your IDE, you can still import the sample projects, export them as APKs and run them on an Android device.

To set up your Android Studio development environment to work with the IAP sample apps:

  1. Extract the contents of the Amazon-Android-SDKs.zip file somewhere to your local machine.
  2. Start Android Studio.
  3. Import the IAP sample apps to your workspace:

    1. On the Welcome to Android Studio screen, select Import Project (Eclipse ADT, Gradle, etc.) to open a project import window.
    2. On the Select Eclipse or Gradle Project to Import window, navigate to the location where you extracted the contents of the Amazon-Android-SDKs.zip file, then navigate to and select /AmazonInAppPurchasing/examples.
    3. Select the directory of one of the three IAP sample projects, and click OK to go to the Import Project from ADT screen.
    4. On the Import Project from ADT screen, select a destination directory, and click Next.
    5. On the screen that follows, leave all of the default settings checked, and click Finish to import the IAP sample app project.
    6. Repeat these steps for each sample app.
  4. Add the IAP 2.0 JAR/library file:
    1. From the upper-left corner of Android Studio (just under the tab for your project), select Project from the drop-down menu (other choices are Android or Packages) to display a directory tree for your project.
    2. Under the app directory for your project, create a new directory and name it "libs".
    3. Copy the IAP 2.0 JAR file to your new libs directory.

      If you are using a Mac, right-click the libs file, and select Reveal in Finder from the context menu. You will then be able to copy the IAP 2.0 JAR file from AmazonInAppPurchasing to your new libs directory. When the directory refreshes, you will see the file in this directory in Android Studio.

    4. Right-click the IAP 2.0 JAR file, and select Add as Library…

      The IAP library will be added to the list of gradle dependencies for your project. You should be able to successfully build the sample app project now.

      Note: If you would prefer to use gradle to add the library, open your build.gradle file and add the following code to the dependencies section of this file, then click the Sync Now link at the top of your build.gradle file to sync your changes:

      dependencies {
      ...
      compile fileTree(dir: 'libs', include: ['*.jar'])
      }
      
    5. Repeat these steps for each sample app project.
  5. Generate the APK for one of the sample apps:
    1. Connect your Android mobile device to your development computer.
    2. In Android Studio, click Debug, and select your running device to install the app to that device.

You should now be able to run this sample app on your mobile device.

Note that when submitting your actual app to the Amazon Appstore, an Amazon signature will be applied to your app, regardless of whether you submit a signed or unsigned APK.

R8 Optimization Incompatible with IAP

The latest update to Android Studio (using Gradle 3.4.0 or higher) applies a default optimization from the R8 compiler that currently causes IAP purchases to fail in the Amazon Appstore. According to the Shrink, obfuscate, and optimize your app in the Android documentation:

When you build your project using Android Gradle plugin 3.4.0 or higher, the Gradle longer uses ProGuard to perform compile-time code optimization. Instead, Gradle uses the R8 compiler to handle the following compile-time tasks.

Set up App Tester

Amazon provides an App Tester tool for performing unit testing of IAP. You can test out this tool with the IAP sample apps.

To install the App Tester and enable the sample app to run on the App Tester:

  1. Follow the instructions in Installing and Configuring the App Tester.
  2. From the sample app, using the adb push command, copy the amazon.sdktester.json file to the /mnt/sdcard/amazon.sdktester.json path on your device:

    $ adb push <_Your_JSON_File_Folder_>/amazon.sdktester.json /mnt/sdcard/`  
    
  3. Follow the instructions in the App Tester User Guide to learn more about testing an app with App Tester. If you need help setting up the test cases to check with the App Tester, see Defining and Executing Test Cases for IAP.

Submit Your App and In-App Items

After you finish testing your app, you can submit your app and in-app items to Amazon.

See Create and Submit IAP Items.