Page updated Apr 3, 2024

Set up fullstack project

👋 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

1npm install -g @aws-amplify/cli
1curl -sL https://aws-amplify.github.io/amplify-cli/install | bash && $SHELL
1curl -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:
1cd ~/Developer/Todo
  1. To create the Amplify project, first you will need to use the amplify CLI you previously installed. Run the command:
1amplify init

Enter the following when prompted:

1? Enter a name for the project
2 `Todo`
3? Initialize the project with the above configuration?
4 `No`
5? Enter a name for the environment
6 `dev`
7? Choose your default editor:
8 `Android Studio`
9? Choose the type of app that you're building
10 `android`
11? Where is your Res directory:
12 `app/src/main/res`
13? Select the authentication method you want to use:
14 `AWS profile`
15? Please choose the profile you want to use
16 `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:

1android {
2 compileOptions {
3 // Support for Java 8 features
4 coreLibraryDesugaringEnabled true
5 sourceCompatibility JavaVersion.VERSION_1_8
6 targetCompatibility JavaVersion.VERSION_1_8
7 }
8}
9
10dependencies {
11 // Amplify API and Datastore dependencies
12 implementation 'com.amplifyframework:aws-api:ANDROID_VERSION'
13 implementation 'com.amplifyframework:aws-datastore:ANDROID_VERSION'
14
15 // Support for Java 8 features
16 coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
17}
  • 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! 🎉