Migrate to v2
Mapbox Navigation SDK for Android v2 is a major new version of the SDK. To install the latest version of the SDK, follow the installation instructions and use this guide to update your application from v1 to v2.
Requirements
Like in v1, the Mapbox Navigation SDK for Android v2 is compatible with applications that:
- Use the Android SDK 21 or higher.
- Use Java 8 for
sourceCompatibility
andtargetCompatibility
, as shown in the installation guide.
Artifacts
v1
In v1 there were two artifacts to choose from:
com.mapbox.navigation:core:{version}
: To use the Navigation SDK without pre-built UI components.com.mapbox.navigation:ui:{version}
: To use the Navigation SDK with pre-built UI components, which also includesnavigation:core
as a dependency.
v2
In Navigation SDK v2, all features are available under one Maven artifact: com.mapbox.navigation:android:{version}
.
Besides the one grouping artifact, there are also multiple granular ones that you can pick-and-choose if you’re not planning to use all the features and want to reduce the binary size of your application:
com.mapbox.navigation:core
offers all the core localization features from v1.com.mapbox.navigation:ui-maps
offers the route line and arrow APIs, navigation camera, building highlight and extrusion, extended visual guidance, and other tools and features that integrate with the Mapbox Maps SDK.com.mapbox.navigation:ui-maneuver
offers the maneuver view and its APIs that replace v1'sInstructionView
.com.mapbox.navigation:ui-tripprogress
offers the trip progress view and APIs that replace v1'sSummaryBottomSheet
.com.mapbox.navigation:ui-voice
offers all necessary APIs to play voice instructions.com.mapbox.navigation:ui-speedlimit
offers the speed limit view and its APIs that replace v1'sSpeedLimitView
.
Read more about leveraging the Navigation SDK v2's modular architecture.
Dependencies
Maps SDK
In v2, the Navigation SDK upgrades to Mapbox Maps SDK v10. Maps SDK v10 offers 3D maps and improved performance.
Maps SDK v10 is also a SEMVER major release with breaking API changes. If the application you are migrating uses a map, make sure you read the Maps SDK migration guide before reading the navigation-specific content below.
Upgrade your application from the Mapbox Maps SDK for Android v9 to v10.
Kotlin
The Navigation SDK v2 is written 100% in Kotlin, the official language recommended by Google for Android development. This is a change from how the previous versions were a mix of Java and Kotlin.
Java support
While the Mapbox Navigation SDK for Android is built with Kotlin, Kotlin is 100% interoperable with Java. Applications with a Java codebase can interact properly with the public APIs exposed by Mapbox SDKs for Android.
For information on Java and Kotlin interoperability see the offical Kotlin docs:
If you experience any issues using the Mapbox Navigation SDK for Android with Java, contact us.
Core components in v2
Core localization components in the Navigation SDK v2 are mostly unchanged architecturally, but introduce a couple breaking changes that improve the experience or clarify the behavior of the SDK to streamline the integration.
The following symbols were removed, renamed, or changed:
- Requesting a route with
MapboxNavigation#requestRoutes
no longer automatically sets the result as the primary route. MapboxNavigation#defaultNavigationOptionsBuilder
has been removed.OnboardRouterOptions
was renamed toRoutingTilesOptions
.- The default directory for caches changed from
APP_FOLDER/Offline/api.mapbox.com/$tilesVersion/tiles
toAPP_FOLDER/mbx_nav/tiles/api.mapbox.com
.
Request a route
MapboxNavigation#requestRoutes
no longer automatically sets the result as the primary route for the navigation experience. This means that you should call MapboxNavigation#setRoutes
with a result when calling MapboxNavigation#requestRoutes
.
This change allows for dispatching and managing multiple route requests concurrently, including canceling with MapboxNavigation#cancelRouteRequest
.
v1
mapboxNavigation?.requestRoutes(
RouteOptions.builder().applyDefaultParams()
.accessToken(Utils.getMapboxAccessToken(applicationContext))
.coordinates(originLocation.toPoint(), null, latLng.toPoint())
.profile(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC)
.build(),
routesReqCallback
)
private val routesReqCallback = object : RoutesRequestCallback {
override fun onRoutesReady(routes: List<DirectionsRoute>) {
if (routes.isNotEmpty()) {
directionRoute = routes[0]
navigationMapboxMap?.drawRoute(routes[0])
startNavigation.visibility = View.VISIBLE
} else {
startNavigation.visibility = View.GONE
}
}
override fun onRoutesRequestFailure(throwable: Throwable, routeOptions: RouteOptions) {
// Handle error
}
override fun onRoutesRequestCanceled(routeOptions: RouteOptions) {
// Handle cancelation
}
}
v2
val routeOptions = RouteOptions.builder()
.applyDefaultNavigationOptions()
.applyLanguageAndVoiceUnitOptions(this)
.coordinates(
origin = origin,
destination = destination
)
.layersList(listOf(mapboxNavigation.getZLevel(), null))
.build()
mapboxNavigation.requestRoutes(
routeOptions,
object : RouterCallback {
override fun onRoutesReady(
routes: List<DirectionsRoute>,
routerOrigin: RouterOrigin
) {
mapboxNavigation.setRoutes(routes)
}
override fun onFailure(
reasons: List<RouterFailure>,
routeOptions: RouteOptions
) {
// no impl
}
override fun onCanceled(routeOptions: RouteOptions, routerOrigin: RouterOrigin) {
// no impl
}
}
)
Read more about requesting routes using the Navigation SDK v2.