2

In my project I use mapbox_gl: ^0.14.0.

When running flutter build aar command it fails with:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mapbox_gl:generateDebugRFile'.
> Could not resolve all files for configuration ':mapbox_gl:debugCompileClasspath'.
   > Could not resolve com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.2.
     Required by:
         project :mapbox_gl
      > Could not resolve com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.2.
         > Could not get resource 'https://api.mapbox.com/downloads/v2/releases/maven/com/mapbox/mapboxsdk/mapbox-android-sdk/9.6.2/mapbox-android-sdk-9.6.2.pom'.
            > Could not HEAD 'https://api.mapbox.com/downloads/v2/releases/maven/com/mapbox/mapboxsdk/mapbox-android-sdk/9.6.2/mapbox-android-sdk-9.6.2.pom'. Received status code 401 from server: Unauthorized
   > Could not resolve com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.2.
     Required by:
         project :mapbox_gl > com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.9.0
      > Could not resolve com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.2.
         > Could not get resource 'https://api.mapbox.com/downloads/v2/releases/maven/com/mapbox/mapboxsdk/mapbox-android-sdk/9.6.2/mapbox-android-sdk-9.6.2.pom'.
            > Could not HEAD 'https://api.mapbox.com/downloads/v2/releases/maven/com/mapbox/mapboxsdk/mapbox-android-sdk/9.6.2/mapbox-android-sdk-9.6.2.pom'. Received status code 401 from server: Unauthorized
   > Could not resolve com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.2.
     Required by:
         project :mapbox_gl > com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v9:0.12.0
         project :mapbox_gl > com.mapbox.mapboxsdk:mapbox-android-plugin-offline-v9:0.7.0
      > Could not resolve com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.2.
         > Could not get resource 'https://api.mapbox.com/downloads/v2/releases/maven/com/mapbox/mapboxsdk/mapbox-android-sdk/9.6.2/mapbox-android-sdk-9.6.2.pom'.
            > Could not HEAD 'https://api.mapbox.com/downloads/v2/releases/maven/com/mapbox/mapboxsdk/mapbox-android-sdk/9.6.2/mapbox-android-sdk-9.6.2.pom'. Received status code 401 from server: Unauthorized

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 30s

Gradle task assembleAarDebug failed with exit code 1.

Also flutter doctor:

[✓] Flutter (Channel stable, 2.8.0, on macOS 12.0.1 21A559 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.63.2)
[✓] Connected device (2 available)

I think it's the problem with secret token since it gives me Unauthorized 401 from server.

I made sure that I put it in my global (not project) gradle.properties the secret key like this: MAPBOX_DOWNLOADS_TOKEN=sk.eyJ1Ij... I saw in another thread that maybe it should be MAPBOX_DOWNLOAD_TOKEN instead of MAPBOX_DOWNLOADS_TOKEN but it did not help.

My secret token has all PUBLIC SCOPES ticked and DOWNLOADS:READ ticked in SECRET SCOPES

So maybe my project simply not reading it but I don't know why.

1 Answers1

0

You can find documentation of Mapbox GL for android here: https://docs.mapbox.com/android/maps/guides/install/.

As said by the mapbox_gl plugin developers, this is community driven not an official Mapbox product.

So, do only the https://docs.mapbox.com/android/maps/guides/install/#configure-credentials part of the documentation for the flutter android project.

  • Create a secret access token with the Downloads:Read scope.

  • Configure your secret token in android/gradle.properties as MAPBOX_DOWNLOADS_TOKEN=YOUR_SECRET_MAPBOX_ACCESS_TOKEN

  • Configure permissions in app/source/main/AndroidManifest.xml as:

    <!-- Always include this permission -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    
    <!-- Include only if your app benefits from precise location access. -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    
  • Keep in mind to provide the same secret key in the accessToken property of the MapboxMap widget in your project.