This guide lists the build configuration requirements for using the Navigation SDK for Android version 5.0.0 and later.
The instructions assume you have an Android IDE installed and are familiar with Android development.
Minimum requirements for using Navigation SDK
These requirements apply to Navigation SDK for Android versions 5.0.0 and later.
A Google Cloud Console project with the Navigation SDK enabled. For provisioning, ask your Google Maps Platform representative.
Your app must target API level 33 or higher.
To run an app built with the Navigation SDK, the Android device must have Google Play services installed and enabled.
Attributions and licensing text must be added to the app.
Set up your projects: Cloud Console project and Android project
Before you can build or test an app, you need to create a Cloud Console project and add API key credentials. The project must have provisioning to access the Navigation SDK. All keys within the Cloud Console project are granted the same access to the Navigation SDK. A key can have more than one development project associated with it. If you already have a console project, you can add a key to your current project.
To set up
- In your favorite web browser, sign in to the Cloud Console and create your Cloud Console project.
- In your IDE, such as Android Studio, create an Android app development project and note the package name.
- Contact your Google Maps Platform representative to provide access to the Navigation SDK for your Cloud Console project.
- While on the Cloud Console dashboard in your web browser, create credentials to generate an API key with restrictions.
- On the API key page, click Android apps in the Application restrictions area.
- Click Add the package name and fingerprint, and then enter the package name of your development project and the SHA-1 fingerprint for that key.
- Click Save.
Add the Navigation SDK to your project
The Navigation SDK is available through Maven. After you create your development project, you can integrate the SDK into it by using one of the following approaches.
Using Maven for Navigation SDK v4.5 and later (recommended)
The following uses the google()
Maven repository, which is the simplest
and recommended way to add Navigation SDK to your
project.
Add the following dependency to your Gradle or Maven configuration, substituting the
VERSION_NUMBER
placeholder for the desired version of Navigation SDK for Android.Gradle
Add the following to your module-level
build.gradle
:dependencies { ... implementation 'com.google.android.libraries.navigation:navigation:VERSION_NUMBER' }
If upgrading from the original Maven repository, note that the group and artifact names have changed, and the
com.google.cloud.artifactregistry.gradle-plugin
plugin is no longer necessary.And add the following to your top-level
build.gradle
:allprojects { ... // Required: you must exclude the Google Play service Maps SDK from // your transitive dependencies. This is to ensure there won't be // multiple copies of Google Maps SDK in your binary, as the Navigation // SDK already bundles the Google Maps SDK. configurations { implementation { exclude group: 'com.google.android.gms', module: 'play-services-maps' } } }
Maven
Add the following to your
pom.xml
:<dependencies> ... <dependency> <groupId>com.google.android.libraries.navigation</groupId> <artifactId>navigation</artifactId> <version>VERSION_NUMBER</version> </dependency> </dependencies>
If you have any dependencies that use the Maps SDK, you have to exclude the dependency in each declared dependency that relies on the Maps SDK.
<dependencies> <dependency> <groupId>project.that.brings.in.maps</groupId> <artifactId>MapsConsumer</artifactId> <version>1.0</version> <exclusions> <!-- Navigation SDK already bundles Maps SDK. You must exclude it to prevent duplication--> <exclusion> <!-- declare the exclusion here --> <groupId>com.google.android.gms</groupId> <artifactId>play-services-maps</artifactId> </exclusion> </exclusions> </dependency> </dependencies>
Using Maven for Navigation SDK prior to v4.5, or with Driver SDK
Navigation SDK continues to be available through the
original Maven repository through the remainder of the v4 versions. This is the
same library with all the same updates as the version above, and provides
compatibility with Driver SDK and other libraries during the transition. Using
this dependency requires logging into your cloud project using gcloud
when
compiling.
- Set up your environment to access Google's Maven repository as described in the Prerequisites section of the Consumer SDK documentation. Access to the Navigation SDK is controlled through a workspace group.
Add the following dependency to your Gradle or Maven configuration, substituting the
VERSION_NUMBER
placeholder for the desired version of Navigation SDK.Gradle
Add the following to your module-level
build.gradle
:dependencies { ... implementation 'com.google.android.maps:navsdk:VERSION_NUMBER' }
And add the following to your top-level
build.gradle
:allprojects { ... // Required: you must exclude the Google Play service Maps SDK from // your transitive dependencies. This is to ensure there won't be // multiple copies of Google Maps SDK in your binary, as the Navigation // SDK already bundles the Google Maps SDK. configurations { implementation { exclude group: 'com.google.android.gms', module: 'play-services-maps' } } }
Maven
Add the following to your
pom.xml
:<dependencies> ... <dependency> <groupId>com.google.android.maps</groupId> <artifactId>navsdk</artifactId> <version>VERSION_NUMBER</version> </dependency> </dependencies>
If you have any dependencies that use the Maps SDK, you have to exclude the dependency in each declared dependency that relies on the Maps SDK.
<dependencies> <dependency> <groupId>project.that.brings.in.maps</groupId> <artifactId>MapsConsumer</artifactId> <version>1.0</version> <exclusions> <!-- Navigation SDK already bundles Maps SDK. You must exclude it to prevent duplication--> <exclusion> <!-- declare the exclusion here --> <groupId>com.google.android.gms</groupId> <artifactId>play-services-maps</artifactId> </exclusion> </exclusions> </dependency> </dependencies>
Configure the build
After you have created the project, you can configure the settings for a successful build and use of the Navigation SDK.
Update local properties
- In the Gradle Scripts folder, open the
local.properties
file and addandroid.useDeprecatedNdk=true
.
Update the Gradle build script
Open the
build.gradle (Module:app)
file and use the following guidelines to update the settings to meet the requirements for Navigation SDK and consider setting the optimization options as well.Required settings for Navigation SDK
- Set
minSdk
to 23 or higher. - Set
targetSdk
to 33 or higher. - Add a
dexOptions
setting that increases thejavaMaxHeapSize
. - Set the location for additional libraries.
- Add the
repositories
anddependencies
for the Navigation SDK. - Replace the version numbers in the dependencies with the latest available versions.
Optional settings to decrease build time
- Enable code shrinking and resource shrinking using R8/ProGuard to remove unused code and resources from dependencies. If the R8/ProGuard step takes too much time to run, consider enabling multidex for development work.
- Reduce the number of language translations included in the build: Set
resConfigs
for one language during development. For the final build, setresConfigs
for languages you actually use. By default, Gradle includes resource strings for all languages supported by the Navigation SDK.
Add desugaring for Java8 support
- If you're building your app using the Android Gradle plugin 4.0.0 or higher, the plugin extends support for using a number of Java 8 language APIs. See Java 8 desugaring support for more information. See the example build script snippet below for how compile and dependency options.
- Set
Below is an example of the Gradle build script for the application. Check the sample apps for updated sets of dependencies, as the version of Navigation SDK you are using may be slightly ahead or behind this documentation.
apply plugin: 'com.android.application'
apply plugin: 'com.google.cloud.artifactregistry.gradle-plugin'
ext {
androidxLifecycleVersion = "2.4.1"
glideVersion = "4.13.2"
navSdk = "__NAVSDK_VERSION__"
}
android {
compileSdk 33
buildToolsVersion='28.0.3'
defaultConfig {
applicationId "<your id>"
// Navigation SDK supports SDK 23 and later.
minSdk 23
targetSdk 33
versionCode 1
versionName "1.0"
// Set this to the languages you actually use, otherwise you'll include resource strings
// for all languages supported by the Navigation SDK.
resConfigs "en"
multiDexEnabled true
}
dexOptions {
// This increases the amount of memory available to the dexer. This is required to build
// apps using the Navigation SDK.
javaMaxHeapSize "4g"
}
buildTypes {
// Run ProGuard. Note that the Navigation SDK includes its own ProGuard configuration.
// The configuration is included transitively by depending on the Navigation SDK.
// If the ProGuard step takes too long, consider enabling multidex for development work
// instead.
all {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
// This tells Gradle where to look to find additional libraries - in this case, the
// google_navigation_navmap.aar file.
repositories {
flatDir {
dirs 'libs'
}
google()
// Required for accessing the Navigation SDK on Google's Maven repository.
maven {
url "artifactregistry://us-west2-maven.pkg.dev/gmp-artifacts/transportation"
}
}
dependencies {
// Include the Google Navigation SDK.
// Note: remember to exclude Google play service Maps SDK from your transitive
// dependencies to avoid duplicate copies of the Google Maps SDK.
api "com.google.android.maps:navsdk:${navSdk}"
// Add: android.useDeprecatedNdk=true
// to local.properties.
api "org.chromium.net:cronet-fallback:76.3809.111"
// Optional for Cronet users:
// api "org.chromium.net:cronet-api:69.3497.100"
// Add LeakCanary to debugImplementation because LeakCanary should only run
// in debug builds.
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
// And dependencies.
api "androidx.appcompat:appcompat:1.6.1"
api "androidx.cardview:cardview:1.0.0"
api "androidx.constraintlayout:constraintlayout:2.0.4"
api "androidx.legacy:legacy-support-v4:1.0.0"
api "androidx.lifecycle:lifecycle-common-java8:${androidxLifecycleVersion}"
api "androidx.lifecycle:lifecycle-process:${androidxLifecycleVersion}"
api "androidx.mediarouter:mediarouter:1.3.0"
api "androidx.preference:preference:1.1.1"
api "androidx.recyclerview:recyclerview:1.2.1"
api "androidx.tracing:tracing:1.0.0"
api "com.github.bumptech.glide:glide:${glideVersion}"
api "com.google.android.datatransport:transport-api:3.0.0"
api "com.google.android.datatransport:transport-backend-cct:3.1.4"
api "com.google.android.datatransport:transport-runtime:3.1.4"
api "joda-time:joda-time:2.10.14"
// Also include the Google Places SDK, which is used by this example, but
// isn't required by the Navigation SDK.
api "com.google.android.libraries.places:places:2.5.0"
api "com.google.android.material:material:1.5.0"
api 'org.jetbrains.kotlin:kotlin-reflect:1.6.21'
api 'org.jetbrains.kotlin:kotlin-stdlib:1.6.21'
api 'com.google.guava:guava:31.0.1-android'
annotationProcessor "androidx.annotation:annotation:1.2.0"
annotationProcessor "com.github.bumptech.glide:compiler:${glideVersion}"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.9'
}
Add the API key to your app
This section describes how to store your API key so that it can be securely referenced by
your app. You should not check your API key into your version control system, so we recommend
storing 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.
To streamline this task, we recommend that you use the Secrets Gradle Plugin for Android. To install the plugin and store your API key:
- In Android Studio, open your project-level
build.gradle
file and add the following code to thedependencies
element underbuildscript
.plugins { // ... id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false }
- Next, open your module-level
build.gradle
file and add the following code to theplugins
element.id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
- Save the file and 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
- Save the file.
- 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}" />
Note: As shown above,
com.google.android.geo.API_KEY
is the recommended metadata name
for the API key. A key with this name can be used to authenticate to multiple
Google Maps-based APIs on the Android platform, including the
Navigation SDK for Android. For backwards compatibility, the API also
supports the name com.google.android.maps.v2.API_KEY
. This legacy
name allows authentication to the Android Maps API v2 only. An application can
specify only one of the API key metadata names. If both are specified, the API
throws an exception.
Include the required attributions in your app
If you use the Navigation SDK for Android in your app, you must include attribution text and open source licenses as part of your app's legal notices section.
You can find the required attribution text and open source licenses in the Navigation SDK for Android zip file:
NOTICE.txt
LICENSES.txt
If you are a Mobility or Fleet Engine Deliveries customer
If you are a Mobility or Fleet Engine Deliveries customer, learn about billing in the Mobility documentation. For more information about recording transactions, see Set up billing, Record billable transactions, Reporting, and Record billable transactions (Android).