To set up and configure a Google Cloud Console project to use the Driver SDK for Android, follow these steps.
- Set up your mobile app project.
- Add the Driver 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 mobile app project
This section describes how to configure your mobile app project for the Driver SDK.
To configure your mobile app project, follow these steps:
- 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 more information, see Create your Fleet Engine project.
- In the Google Cloud Console, select the same Google Cloud Console project and API key that you are using for Fleet Engine.
- Select APIs & Services and search for and enable the Maps SDK for Android.
Add the Driver SDK to your app
The Driver SDK is available from the Google Maven repository. The repository includes the SDK's Project Object Model (.pom) files and Javadocs.
To add the Driver SDK to your app, add the Driver SDK and Navigation SDK dependencies to your Gradle or Maven configuration.
In the following example, substitute VERSION_NUMBER
with the selected version
of the Driver SDK.
Gradle
Add the following to your build.gradle
:
dependencies {
...
implementation 'com.google.android.libraries.mapsplatform.transportation:transportation-driver:VERSION_NUMBER'
implementation 'com.google.android.libraries.navigation:navigation:5.0.0'
}
Maven
Add the following to your pom.xml
:
<dependencies>
...
<dependency>
<groupId>com.google.android.libraries.mapsplatform.transportation.driver</groupId>
<artifactId>transportation-driver</artifactId>
<version>VERSION_NUMBER</version>
</dependency>
<dependency>
<groupId>com.google.android.libraries.navigation</groupId>
<artifactId>navigation</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
Add the API key to your app
Once you have added the Driver 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 mobile app project.
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, follow these steps:
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.
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.driverapidemo" >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_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 Driver 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 Include open source notices on how to include open source notices.