Search code examples
nativescriptmapbox-gl

@nativescript-community/ui-mapbox : Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0


I'm trying to use @nativescript-community/ui-mapbox plugin in my nativesctipt app.

After adding the plugin to my application

ns plugin add @nativescript-community/ui-mapbox
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:map="@nativescript-community/ui-mapbox" navigatingTo="navigatingTo">
  <StackLayout>
    <Label text="Nice map, huh!" class="title"/>
    <ContentView height="240" width="240">
      <map:MapboxView
          accessToken="your_token"
          mapStyle="traffic_night"
          latitude="52.3702160"
          longitude="4.8951680"
          zoomLevel="3"
          showUserLocation="true"
          mapReady="onMapReady">
      </map:MapboxView>
    </ContentView>
  </StackLayout>
</Page>

When running the tns run android command, I get the following error:

Build file '/Users/Mac/lete/letesell/platforms/android/app/build.gradle' line: 575
A problem occurred configuring project ':app'.
Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0.
Required by:
    project :app
    project :app > com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.0

Solution

    1. Generate a token with Downloads:Read permission (see detailed doc)
    2. Add this to your App_Resources/Android/app.gradle and replace DOWNLOAD_TOKEN with the one you generated :
    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"
          // You can store secret token in gradle.properties for more security
          password = "DOWNLOAD_TOKEN"
        }
      }
    }
    
    1. Change minSdkVersion to 21 (or whatever the doc says) in your App_Resources/Android/app.gradle