Project setup

VERSION 0.32.0
PUBLIC PREVIEW

This guide describes how you can set up your Android project to use the TomTom Maps SDK. After completing the guide you should have an empty Android project that works using Maps SDK dependencies.

  1. Install Android Studio if you don’t already have it.
  2. Create a new project or open an existing one. Make sure that the minimum SDK API level is set to at least 21 (Android 5.0 "Lollipop").
    1android {
    2 ...
    3 defaultConfig {
    4 ...
    5 minSdk 21
    6 ...
    7 }
    8 ...
    9}
  3. Make sure to use Gradle in your project. We are no longer supporting Maven. Contact us if your project is using Maven instead of Gradle.
  4. Add the following packaging options to the android block in the build.gradle file of your application module (app/build.gradle).
    1android {
    2 ...
    3 packagingOptions {
    4 jniLibs.pickFirsts.add("lib/**/libc++_shared.so")
    5 }
    6}

Configuring project dependencies

  1. Add a maven block to your settings.gradle file to specify the credentials and the URI for repositories.tomtom.com.

    1dependencyResolutionManagement {
    2 repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    3 repositories {
    4 google()
    5 mavenCentral()
    6 maven {
    7 url = uri("https://repositories.tomtom.com/artifactory/maven")
    8 }
    9 }
    10}
  2. Verify that everything works as expected by adding a Maps SDK dependency to the build.gradle file of your application module. For example, com.tomtom.sdk.maps:map-display. Synchronize the project.

    1dependencies {
    2 def version = "0.32.0"
    3 implementation "com.tomtom.sdk.maps:map-display:$version"
    4}
  3. Get your TomTom API key from the TomTom Developer Portal. To find out how, refer to the How to get a TomTom API key guide.

  4. Store the TomTom API key to a project property in your project gradle.properties file. Replace api_key_placeholder with the actual TomTom API key.

    tomtomApiKey=api_key_placeholder
  5. Map the TomTom API key property to a custom field of the gradle BuildConfig class in the build.gradle file of your application module.

    1android {
    2 ...
    3 buildFeatures {
    4 buildConfig = true
    5 }
    6 buildTypes.each {
    7 it.buildConfigField 'String', 'TOMTOM_API_KEY', "\"$tomtomApiKey\""
    8 }
    9}

    To use the TomTom API key in your application code, it is sufficient to access the newly added BuildConfig field.

    val apiKey = BuildConfig.TOMTOM_API_KEY

Now that you’ve completed the project setup, here is what you can do next.

Learn more

After a successful project setup, you can visit the following pages with some useful suggestions on how to proceed: