How to solve : Failed to resolve: com.mapbox.mapboxsdk:mapbox-android-sdk:9.5.0

Viewed 9785

I face this problem when trying to use mapbox in Android studio
Failed to resolve: com.mapbox.mapboxsdk:mapbox-android-sdk:9.5.0

what is the problem?

my build.gradle dependencies


dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.5.0'
}

my build.gradle project

buildscript {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.1"
    }
}

allprojects {
    repositories {
  google()
        jcenter()
        maven { url 'https://mapbox.bintray.com/mapbox' }

    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}
8 Answers

it's just badly explained. you have to make a private token. public token does not work. when you create a token there is a field with "Read:Download" just mark it and generate your token. This token should work.

Version 9.5.0 (and 9.6.0) also exists (See release notes here: https://github.com/mapbox/mapbox-gl-native-android/blob/main/CHANGELOG.md). It is just that the way to access the Maven repository has changed with Mapbox Maps SDK > v9.4.0.

I would discourage you from using an outdated version like mapbox-android-sdk:8.6.7, but go for com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.0.

The new way to access the mave repo is documented here: https://docs.mapbox.com/android/maps/overview/#configure-credentials

You now need to create a secret access token and use it to access the maven repo, where the libraries are located. Your module level build.gradle should contain this:

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

Just use this safe version and it will work on your gradle.

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

Found Solution by generating private key as pointed out in previous answers, and finding an actual version on maven central, neither 9.7 nor 10 was on the maven central repository at the time of writing, using version 9.2 found here

https://mvnrepository.com/artifact/com.mapbox.mapboxsdk/mapbox-android-sdk

Edit: Was able to use 9.7.0 mapbox by changing settings.gradle entry

repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

to

repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)

and build.gradle to add mavenCentral() and google() to allprojects repositories

allprojects {
    repositories {
        google()
        mavenCentral()
        
        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'] ?: ""
                    }
                }
            }
        }
    }
}

The only way got my project to finally work is by looking for some pointers in the project attached here: https://github.com/mapbox/mapbox-maps-android/issues/614#issue-988592394 It uses com.mapbox.maps:android:10.0.0-rc.3 and actually works on my machine.

To make my own project work, I had to change settings.gradle from this:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}
rootProject.name = "Mapbox Map"
include ':app'

to this:

rootProject.name = "Mapbox Map"
include ':app'

screenshot

The default token Mapbox provides you is what I think you're using, you need to create a new private token and check this permission DOWNLOAD:READ then it should work.

I created a new token and named it first in my case, you can call it anything.

You should remove this line : maven{ url 'https://mapbox.bintray.com/mapbox' }

 repositories {
    google()
    jcenter()
    mavenCentral()
    /**
    if you using => maven { url 'https://mapbox.bintray.com/mapbox' }
     so remove this line because mapbox remove repository from https://mapbox.bintray.com/mapbox
    * */
    maven { url "https://oss.sonatype.org/content/groups/public/" }
    maven { url 'https://jitpack.io' }
    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'] ?: ""
        }
    }
}

How about trying a version, which actually exists?

implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.7'
Related