Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Oct 24, 2024

Set up fullstack project

For new Amplify apps, we recommend using Amplify Gen 2. You can learn more in our Gen 2 Docs.

👋 Welcome! In this tutorial, you will:

  • Set up an Android application configured with Amplify
  • Create a data model and persist data to Amplify DataStore
  • Connect your local data to synchronize to a cloud backend

Prerequisites

npm install -g @aws-amplify/cli
curl -sL https://aws-amplify.github.io/amplify-cli/install | bash && $SHELL
curl -sL https://aws-amplify.github.io/amplify-cli/install-win -o install.cmd && install.cmd

Create a new Android application

  1. Open Android Studio. Select New Project.

    Shows the Android studio welcome window

  2. Select Empty Activity. Press Next.

    Shows Android studio select project template window

  3. Fill in the following for your project:

    • Name: Todo
    • Language: Kotlin or Java
    • Minimum SDK: API 24: Android 7.0 (Nougat)
    • Press Finish

Shows android studio configure project window

You should now have an empty Android project without Amplify.

Add Amplify to your application

If you prefer, you can create the Amplify project with Amplify Studio instead!

Amplify Library for Android is distributed as an Apache Maven package. In this section, you'll add the packages and other required directives to your build configuration.

  1. Open a terminal window and change to the directory for your application project. For example, if you created the previous Todo project in the folder ~/Developer, you can type the following:
cd ~/Developer/Todo
  1. To create the Amplify project, first you will need to use the amplify CLI you previously installed. Run the command:
amplify init

Enter the following when prompted:

? Enter a name for the project
`Todo`
? Initialize the project with the above configuration?
`No`
? Enter a name for the environment
`dev`
? Choose your default editor:
`Android Studio`
? Choose the type of app that you're building
`android`
? Where is your Res directory:
`app/src/main/res`
? Select the authentication method you want to use:
`AWS profile`
? Please choose the profile you want to use
`default`

Upon successfully running amplify init, you will see a configuration file created in ./app/src/main/res/raw/ called amplifyconfiguration.json.

This file will be bundled into your application so that the Amplify libraries know how to reach your provisioned backend resources at runtime.

  1. Under Gradle Scripts, open build.gradle (Module :app).

Add the following lines:

android {
compileOptions {
// Support for Java 8 features
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
// Amplify API and Datastore dependencies
implementation 'com.amplifyframework:aws-api:ANDROID_VERSION'
implementation 'com.amplifyframework:aws-datastore:ANDROID_VERSION'
// Support for Java 8 features
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}
  • Set coreLibraryDesugaringEnabled, sourceCompatibility, and targetCompatibility to allow your application to make use of Java 8 features like Lambda expressions
  • Add Amplify API, Datastore, and Desugaring libraries to the dependencies block
  1. Run Gradle Sync

    Android Studio requires you to sync your project with your new configuration. To do this, click Sync Now in the notification bar above the file editor.

    Screenshot with an arrow pointing to the Sync Now button in the file's notification bar

    When complete, you will see BUILD SUCCESSFUL in the output in the Build tab at the bottom of your screen.

    Shows configuration successful in Android Studio

You are ready to start building with Amplify! 🎉