To set up and configure a Google Cloud Console to use the Consumer SDK for Android, follow these steps.
- Set up your development project.
- Add the Consumer SDK to your app.
- Add the API key to your app.
- Include the required attributions in your app.
For more details on each step, see the following sections.
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 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.
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 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.
To streamline this task, you can use the GitHub documentation Secrets Gradle Plugin for Android.
To install the plugin and store your API key:
Open your root-level
build.gradle
file and add the following code to thedependencies
element underbuildscript
.Groovy
buildscript { dependencies { // ... classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0" } }
Kotlin
buildscript { dependencies { // ... classpath("com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0") } }
Open your app-level
build.gradle
file and add the following code to theplugins
element.Groovy
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
Kotlin
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
If you use Android Studio, sync your project with Gradle. For details, see Sync your project with Gradle in the Android documentation.
Open the
local.properties
in your project level directory, and then add the following code. ReplaceYOUR_API_KEY
with your API key.MAPS_API_KEY=YOUR_API_KEY
In your
AndroidManifest.xml
file, go tocom.google.android.geo.API_KEY
and update theandroid:value
attribute as follows:
<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:
<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.