3

I'm trying to setup the basic tutorial here but i am blocked by errors in Android Studio: https://docs.mapbox.com/android/maps/overview/#install-the-maps-sdk

Error 1: seen when i Sync the build.gradle:

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.mapbox.mapboxsdk:mapbox-android-sdk:9.4.0.

I then added the recommended exclude items and still get the error.

Error 2: It says to run gradle from the command line but that is not found either.

Here's the relevant part of my build.gradle:

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.4.0'
    implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:9.4.0'){
        exclude group: 'group_name', module: 'module_name'
    }
}
glutz
  • 1,889
  • 7
  • 29
  • 44

6 Answers6

1

You can remove the following line

implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:9.4.0'){
        exclude group: 'group_name', module: 'module_name'
    }

You're probably missing the maven block as seen in step #5 of https://docs.mapbox.com/android/maps/overview/#add-the-dependency. Make sure you add it.

Also, have you created a secret token with the right scope? See the second bullet point (A secret access token with the...) at https://docs.mapbox.com/android/maps/overview/#configure-credentials

langsmith
  • 2,529
  • 1
  • 11
  • 13
1

You need to configure the MapBox repository:

allprojects {
  repositories {
    maven {
      url 'https://api.mapbox.com/downloads/v2/releases/maven'
      authentication {
          basic(BasicAuthentication)
      }
      credentials {
          username = 'mapbox'
          // Use the secret token you stored in gradle.properties as the password
          password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
      }
    }
  }
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
1

In my case

MAPBOX_DOWNLOADS_TOKEN="PASTE_YOUR_SECRET_TOKEN_HERE" instead of MAPBOX_DOWNLOADS_TOKEN=PASTE_YOUR_SECRET_TOKEN_HERE.

Just removed quotes and it worked.Just try this.

Abraham Mathew
  • 2,029
  • 3
  • 21
  • 42
1

i also faced this issue , isolved it by using an old version of mapbox the new version has some issue connecting to the mapbox server

try using this or some other version

dependencies{
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.0.0'
}


allprojects {
repositories {
   ...
   mavenCentral()
}
}
Syed Usama Ahmad
  • 1,307
  • 13
  • 22
0

i had changed the username to my own name. apparently it should remain as "mapbox".

glutz
  • 1,889
  • 7
  • 29
  • 44
0

Well i know it is too late but still thought to write an answer as i got same error

here is solution

in your app level gradle file , replace as mentioned below

From

implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.4.0'
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:9.4.0'){
        exclude group: 'group_name', module: 'module_name'
}

To

implementation 'com.mapbox.maps:android:10.11.0'

For Android Studio less than Arctic Fox (2020.3.1) and Gradle less than v6.0: Open up your project-level build.gradle file, and add the code below to declare the endpoint in the repositories block:

allprojects {
    repositories {
        maven {
              url 'https://api.mapbox.com/downloads/v2/releases/maven'
              authentication {
                  basic(BasicAuthentication)
              }
              credentials {
                // Do not change the username below.
                // This should always be `mapbox` (not your username).
                  username = "mapbox"
                  // Use the secret token you stored in gradle.properties as the password
                  password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
              }
          }
    }
}

Android Studio Arctic Fox (2020.3.1) or later and Gradle v6.0 or later: You may need to make these declarations in your settings.gradle file instead. If you see build errors with the build.gradle process described above, then instead declare the Mapbox's Maven repository in your settings.gradle file like below:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
          url 'https://api.mapbox.com/downloads/v2/releases/maven'
          authentication {
            basic(BasicAuthentication)
          }
          credentials {
            // Do not change the username below.
            // This should always be `mapbox` (not your username).
            username = "mapbox"
            // Use the secret token you stored in gradle.properties as the password
            password = MAPBOX_DOWNLOADS_TOKEN
          }
        }
    }
}

For more details , you can refer this link https://docs.mapbox.com/android/maps/guides/install/

jayesh gurudayalani
  • 1,368
  • 1
  • 9
  • 14