Search code examples
androidmapsmapbox

Failed to install map box in my android app with Received status code 403 from server: Forbidden


Could not resolve all files for configuration ':app:debugRuntimeClasspath'.

Could not resolve com.mapbox.navigator:mapbox-navigation-native:7.0.0. Required by: project :app > com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.42.6 > com.mapbox.mapboxsdk:mapbox-android-navigation:0.42.6 > Could not resolve com.mapbox.navigator:mapbox-navigation-native:7.0.0. > Could not get resource 'https://mapbox.bintray.com/mapbox/com/mapbox/navigator/mapbox-navigation-native/7.0.0/mapbox-navigation-native-7.0.0.pom'. > Could not GET 'https://mapbox.bintray.com/mapbox/com/mapbox/navigator/mapbox-navigation-native/7.0.0/mapbox-navigation-native-7.0.0.pom'. Received status code 403 from server: Forbidden > Could not resolve com.mapbox.navigator:mapbox-navigation-native:7.0.0. > Could not get resource 'https://api.mapbox.com/downloads/v2/releases/maven/com/mapbox/navigator/mapbox-navigation-native/7.0.0/mapbox-navigation-native-7.0.0.pom'. > Could not GET 'https://api.mapbox.com/downloads/v2/releases/maven/com/mapbox/navigator/mapbox-navigation-native/7.0.0/mapbox-navigation-native-7.0.0.pom'. Received status code 403 from server: Forbidden


Solution

  • The problem:

    you don't have access rights to download mapbox dependencies which need a valid token from your mapbox account.

    Solution:

    First you need to have a mapbox access token with Downloads privieleges: Go to https://account.mapbox.com/access-tokens/create and create an access token with Downloads:READ

    mapbox

    You need to specify the mapbox token on project level gradle, add your token to gradle.properties

    android.useAndroidX=true
    android.enableJetifier=true
    MAPBOX_DOWNLOADS_TOKEN=yourMapBoxKey
    

    take note that you need to enable Downloads:Read scope on your token, if not then you'll get 403: forbidden when build your project

    and on your build.gradle

    buildscript {
        ext.kotlin_version = '1.3.50'
        repositories {
            google()
            jcenter()
            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'] ?: ""
                }
            }
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:4.1.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    

    hope this can help solve the problem.

    refs: https://githubmemory.com/repo/eopeter/flutter_mapbox_navigation/issues/126