Installation
To start developing your application using the Mapbox Java SDK, you'll need to first decide which installation method works for you. The SDK is fully compatible with Android using Gradle and can also be included in a generic Java project using either Gradle or Maven. All the dependencies are served from Mapbox's maven repository, which requires some additional configuration.
Installation with Gradle
- Start Android Studio.
- Open your project's
settings.gradle
file. - Add the Mapbox maven repository to the
repositories
block.
dependencyResolutionManagement {
repositories {
...
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
}
}
}
dependencyResolutionManagement {
repositories {
...
maven {
url = uri("https://api.mapbox.com/downloads/v2/releases/maven")
}
}
}
- Open your project's app-level
build.gradle
file. - Make sure that your project's
minSdkVersion
is API 14 or higher. - In the dependencies block, add a new
implementation
dependency for each Java SDK package you want in your project, as shown below. - Click
Sync Project with Gradle Files
near the toolbar in Android Studio.
dependencies {
...
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-geojson:7.3.1'
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:7.3.1'
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:7.3.1'
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-core:7.3.1'
implementation 'androidx.annotation:annotation:1.0.0'
}
dependencies {
...
implementation("com.mapbox.mapboxsdk:mapbox-sdk-geojson:7.3.1")
implementation("com.mapbox.mapboxsdk:mapbox-sdk-services:7.3.1")
implementation("com.mapbox.mapboxsdk:mapbox-sdk-turf:7.3.1")
implementation("com.mapbox.mapboxsdk:mapbox-sdk-core:7.3.1")
implementation("androidx.annotation:annotation:1.0.0")
}
Installation with Maven
If your project is using Maven instead of Gradle, you can add the dependencies inside your project's POM.xml
file.
Add the Mapbox maven repository
Add the Mapbox maven repository to using a repository
tag.
<project>
...
<repositories>
<repository>
<id>mapbox-repo</id>
<url>https://api.mapbox.com/downloads/v2/releases/maven</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
...
</project>
Add Mapbox Java SDK packages
Add a dependency
tag, including the groupId
, artifactId
, and version
for each package you want to use.
<project>
...
<dependencies>
...
<dependency>
<groupId>com.mapbox.mapboxsdk</groupId>
<artifactId>mapbox-sdk-geojson</artifactId>
<version>7.3.1</version>
</dependency>
<dependency>
<groupId>com.mapbox.mapboxsdk</groupId>
<artifactId>mapbox-sdk-services</artifactId>
<version>7.3.1</version>
</dependency>
<dependency>
<groupId>com.mapbox.mapboxsdk</groupId>
<artifactId>mapbox-sdk-turf</artifactId>
<version>7.3.1</version>
</dependency>
<dependency>
<groupId>com.mapbox.mapboxsdk</groupId>
<artifactId>mapbox-sdk-core</artifactId>
<version>7.3.1</version>
</dependency>
...
</dependencies>
...
</project>
Import and use the Java SDK
You can now import the Java SDK's modules and use them in your java project.
Explore each module's guides to learn key concepts and get usable code snippets:
Explore the API Reference to get a better understanding of all the available classes and methods.
For more inspiration and code snippets for various use cases, see the examples.