Project setup
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.
- Install Android Studio if you don’t already have it.
- 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 216 ...7 }8 ...9}
- 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.
- 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
-
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} -
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} -
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.
-
Store the TomTom API key to a project property in your project
gradle.properties
file. Replaceapi_key_placeholder
with the actual TomTom API key.tomtomApiKey=api_key_placeholder -
Map the TomTom API key property to a custom field of the gradle
BuildConfig
class in thebuild.gradle
file of your application module.1android {2 ...3 buildFeatures {4 buildConfig = true5 }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: