To set up and configure a Google Cloud console to use the Consumer SDK for
Android, follow these steps.

1. [Set up your development project](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/android/configure-project.md.txt#auth-project).
2. [Add the Consumer SDK to your app](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/android/configure-project.md.txt#add-sdk).
3. [Add the API key to your app](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/android/configure-project.md.txt#add-key).
4. [Include the required attributions in your app](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/android/configure-project.md.txt#attrib).

For more details on each step, see the following sections.

> [!NOTE]
> **Note:** Your app must target `minSdkVersion` 23 or higher.

## Set up your development project

If you don't have a Google Cloud console development project and an API key for
your mobility project, you need to set one up. For details, see
[Create your project](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/create-project.md.txt) in the Fleet Engine guide.

When you're selecting your development project for the Consumer SDK, select the
same Google Cloud console project and API key that you are using for Fleet Engine.

## Add the Consumer SDK to your app

The Consumer SDK is available from the Google Maven repository. The repository
includes the SDK's Project Object Model (.pom) files and Javadocs. To add the
Consumer SDK to your app, add the Consumer SDK and Maps SDK dependencies to your
Gradle or Maven configuration.

> [!NOTE]
> **Note:** The Consumer SDK depends on the Maps SDK. Set your dependency to an **explicitly defined** version of Maps SDK, as shown in this example. Otherwise, the Consumer SDK uses the minimum-required version of the Maps SDK, which might cause issues if your app relies on features available in later Maps SDK versions.

In the following examples, substitute `VERSION_NUMBER` with the required
version of the Consumer SDK:

### Gradle

Add the following to your `build.gradle`:

    dependencies {
      ...
      implementation 'com.google.android.libraries.mapsplatform.transportation:transportation-consumer:VERSION_NUMBER'
      implementation "com.google.android.gms:play-services-maps:18.1.0"
    }

### Maven

Add the following to your `pom.xml`:

    <dependencies>
      ...
      <dependency>
        <groupId>com.google.android.libraries.mapsplatform.transportation</groupId>
        <artifactId>transportation-consumer</artifactId>
        <version>VERSION_NUMBER</version>
      </dependency>
      <dependency>
        <groupId>com.google.android.gms</groupId>
        <artifactId>play-services-maps</artifactId>
        <version>18.1.0</version>
      </dependency>
    </dependencies>

## Add the API key to your app

Once you have added the Consumer SDK to your app, add the API key. You must use
the project API key you obtained when you set up your development project. For
more details, see [Set up your development project](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/android/configure-project.md.txt#auth-project) in Step 3 of this guide.

This section describes how to store your API key so that it can be more securely
referenced by your app. For more information on API key security best practices,
see the Google Maps Platform article on [API security best practices](https://developers.google.com/maps/api-security-best-practices.md.txt#restrict_apikey).

> [!IMPORTANT]
> **Important:** Don't check your API key into your version control system. Instead, store it in the `local.properties` file, which is located in the root directory of your project. For more information about the `local.properties` file, see [Gradle properties files](https://developer.android.com/studio/build#properties-files).

To streamline this task, you can use the GitHub documentation [Secrets Gradle
Plugin for Android](https://github.com/google/secrets-gradle-plugin).

To install the plugin and store your API key:

1. Open your root-level `build.gradle` file and add the following code to the
   `dependencies` element under `buildscript`.

   ### Groovy

   ```groovy
   buildscript {
         dependencies {
             // ...
             classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0"
         }
   }
   ```

   ### Kotlin

   ```kotlin
   buildscript {
       dependencies {
           // ...
           classpath("com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0")
       }
   }
   ```
2. Open your app-level `build.gradle` file and add the following code to the
   `plugins` element.

   ### Groovy

   ```groovy
   id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
   ```

   ### Kotlin

   ```kotlin
   id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
   ```
3. If you use Android Studio, sync your project with Gradle. For details, see
   [Sync your project with Gradle](https://developer.android.com/studio/build#sync-files) in the Android documentation.

4. Open the `local.properties` in your project level directory, and then add
   the following code. Replace `YOUR_API_KEY` with your API key.

   MAPS_API_KEY=<var translate="no">YOUR_API_KEY</var>
5. In your `AndroidManifest.xml` file, go to `com.google.android.geo.API_KEY`
   and update the `android:value` attribute as follows:

```html
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="${MAPS_API_KEY}" />
```

The following example shows a complete manifest for a sample app:

```html
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.consumerapidemo">
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/_AppTheme">

            <meta-data
                android:name="com.google.android.geo.API_KEY"
                android:value="${MAPS_API_KEY}" />

            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    </manifest>
```

## Include the required attributions in your app

If you use the Consumer SDK in your app, you must include attribution text and
open source licenses as part of your app's legal notices section. It's best to
include the attributions as an independent menu item or as part of an **About**
menu item.

You can find the license information in the "third_party_licenses.txt" file in
the unarchived AAR file.

Refer to <https://developers.google.com/android/guides/opensource> on how to
include open source notices.

## What's next

[Get authentication tokens](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/android/auth-sdk.md.txt)