Why is mapbox-android sdk not resolving from build.gradle?

Viewed 4398

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'
    }
}
5 Answers

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

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'] ?: ""
      }
    }
  }
}

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.

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()
}
}

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

Related