Project Configuration

This guide lists the build configuration requirements for using the Navigation SDK for Android. The instructions assume you have an Android IDE installed and are familiar with Android development.

Minimum requirements for using Navigation SDK

  • A Google Cloud Console project with the Navigation SDK enabled. For provisioning, ask your Google Maps Platform representative.

  • Your app must target Navigation SDK (Version 16) 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: Google 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

  1. In your favorite web browser, such as Chrome, sign in to the Google Cloud Console and create your Google Cloud Console project.
  2. In your IDE, such as Android Studio, create an Android app development project and note the package name.
  3. Contact your Google Maps Platform representative to provide access to the Navigation SDK for your Google Cloud Console project.
  4. While on the Google Cloud Console dashboard in your web browser, create credentials to generate an API key with restrictions.
  5. On the API key page, click Android apps in the *Application restrictions area.
  6. 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.
  7. Click Save.

Add the Navigation SDK to your app

The Navigation SDK is available as an aar bundle. After creating the development project, you can integrate the SDK. These instructions assume the use of Android Studio for your IDE.

  1. Download and unzip the Navigation SDK zip file.

  2. In Android Studio, open a project and add the Google Play services package using the SDK manager.

  3. From the zip file directory, copy libs/google_navigation.aar into your project's app/libs directory.

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 add android.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

    1. Set minSdkVersion to 16 or above.
    2. Set 'targetSDKversion' for API 21 to shift permissions handling to the API. For previous versions, you need to explicitly include permissions flows in your app.
    3. Add a dexOptions setting that increases the javaMaxHeapSize.
    4. Set the location for additional libraries.
    5. Add the repositories and dependencies for the Navigation SDK.
    6. Replace the version numbers in the dependencies with the latest available versions.

    Optional settings to decrease build time

    • To improve the build time for your app
    • To optimize use of the dependencies, enable ProGuard and resource shrinking. Proguard removes unused code and resources from dependencies. If the proguard step runs too long, 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, set 'resConfigs' for languages you actually use. By default, Gradle includes resource strings for all languages supported by the Navigation SDK.

Below is an example of the Gradle build script for the application.

  
  apply plugin: 'com.android.application'

  ext {
      supportVersion = "27.1.1"
      lifecycle_version = "1.1.1"
  }

  android {
      compileSdkVersion 27
      buildToolsVersion '28.0.3'

      defaultConfig {
          applicationId "com.example.navigationapidemo"
          minSdkVersion 16
          targetSdkVersion 27
          versionCode 1
          versionName "1.0"
          resConfigs "en"
      }

      dexOptions {
          // This increases the amount of memory available to the dexer. This is
          // required to build apps using the Navigation SDK.
          javaMaxHeapSize "4g"
      }
      buildTypes {
          all {
              minifyEnabled true
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
      compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
      }
  }

  // Specify where to find additional libraries and the location of google_navigation.aar file.
  repositories {
      flatDir {
          dirs 'libs'
      }
      google()
  }
  dependencies {
      api fileTree(include: ['*.jar'], dir: 'libs')

      // Include the Google Navigation API library
      api(name: 'google_navigation', ext: 'aar')

      // These dependencies are required for the Navigation API to function
      // properly at runtime.
      api "org.chromium.net:cronet-fallback:69.3497.100"
      // Optional for Cronet users:
      // api "org.chromium.net:cronet-api:69.3497.100"
      api "com.android.support:appcompat-v7:${supportVersion}"
      api "com.android.support:cardview-v7:${supportVersion}"
      api "com.android.support:design:${supportVersion}"
      api "com.android.support:mediarouter-v7:${supportVersion}"
      api "com.android.support:preference-v7:${supportVersion}"
      api "com.android.support:recyclerview-v7:${supportVersion}"
      api 'com.github.bumptech.glide:glide:4.9.0'
      api 'com.github.bumptech.glide:okhttp-integration:4.9.0'
      api "android.arch.lifecycle:common-java8:$lifecycle_version"
      api 'com.google.android.datatransport:transport-api:2.2.0'
      api 'com.google.android.datatransport:transport-backend-cct:2.2.0'
      api 'com.google.android.datatransport:transport-runtime:2.2.0'
      api 'joda-time:joda-time:2.9.9'

      // The Navigation SDK does not require the
      // Places API; however, the demo app for does.
      api 'com.google.android.gms:play-services-places:10.2.1'

      annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
  }

Update your app's manifest

  1. In the Manifest folder, open the AndroidManifest.xml file.

  2. Add your API key within the <application> element. You must use the API key defined in your Google Cloud Console project described in the step above.

    In a partial manifest shown in this example, you would replace YOUR_API_KEY with your own API key:

          <meta-data
              android:name="com.google.android.geo.API_KEY"
              android:value="YOUR_API_KEY"/>
    

    A complete manifest below shows the setting for the API key and the empty intent for the MainActivity that runs on startup.

    
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.navigationapidemo" >
    
          <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="YOUR_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 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

Next step

Learn how to plot a route.