mapbox-maps-flutter icon indicating copy to clipboard operation
mapbox-maps-flutter copied to clipboard

Build fails with exception for Android

Open MilesAdamson opened this issue 1 year ago • 9 comments

I have an existing project I am trying to migrate from google maps to mapbox. When I add mapbox_maps_flutter: ^0.5.0 to my pubspec, and SDK_REGISTRY_TOKEN to my gradle.properties then try to build, I get the error below.

The issue does not appear to be with other dependencies. I can make a brand new flutter project, and build successfully if I copy+paste all the dependencies in from my real project. Any help would be appreciated, I'm not even really sure if this is an issue with this plugin.

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file 'C:\Users\miles\AppData\Local\Pub\Cache\hosted\pub.dev\mapbox_maps_flutter-0.5.0\android\build.gradle' line: 18

* What went wrong:
A problem occurred evaluating project ':mapbox_maps_flutter'.
> Basedir C:\Users\miles\AppData\Local\Pub\Cache\hosted\pub.dev\cloud_firestore_web-3.6.3\android does not exist

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* Where:
Script 'D:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 412

* What went wrong:
A problem occurred configuring project ':mapbox_maps_flutter'.
> Failed to notify project evaluation listener.
   > Could not get unknown property 'android' for project ':mapbox_maps_flutter' of type org.gradle.api.Project.
   > Could not find method implementation() for arguments [project ':flutter_plugin_android_lifecycle'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
   > Could not get unknown property 'android' for project ':mapbox_maps_flutter' of type org.gradle.api.Project.

* 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 11s

My dependencies:


environment:
  sdk: '>=3.0.0 <4.0.0'
  flutter: 3.10.6

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  mapbox_maps_flutter: ^0.5.0
  flutter_js: ^0.7.0
  dio: ^5.1.2
  flutter_spinkit: ^5.1.0
  provider: ^6.0.2
  package_info_plus: ^4.0.2
  url_launcher: ^6.1.0
  flutter_secure_storage: ^8.0.0
  json_serializable: ^6.1.5
  intl: ^0.18.0
  firebase_messaging: ^14.2.1
  sentry: ^7.5.2
  google_maps_flutter: ^2.3.0
  flutter_background_geolocation: ^4.0.2
  permission_handler: ^10.0.0
  firebase_core: ^2.4.1
  cloud_firestore: ^4.3.1
  firebase_auth: ^4.5.0
  firebase_storage: ^11.0.10
  image_picker: ^0.8.5
  retry: ^3.1.0
  flutter_markdown: ^0.6.1
  global_configuration: 2.0.0-nullsafety.1
  flutter_redux: ^0.10.0
  path_provider: ^2.0.9
  file_picker: ^5.0.1
  open_filex: ^4.1.1
  uuid: ^3.0.6
  json_at: ^2.1.0
  custom_refresh_indicator: ^2.0.1
  new_version_plus: ^0.0.4
  version: ^3.0.2
  flutter_keyboard_visibility: ^5.2.0
  cached_network_image: ^3.2.0
  connectivity_plus: ^4.0.0
  messagepack: ^0.2.1
  device_info_plus: ^9.0.0
  community_material_icon: ^5.4.55
  system_proxy: ^0.1.0
  flutter_cache_manager: ^3.3.0
  dotted_border: ^2.0.0+2
  easy_debounce: ^2.0.2+1
  flutter_local_notifications: ^14.0.0+1
  azblob: ^2.3.0
  json_schema2: ^2.0.2
  collection: ^1.16.0
  redux: ^5.0.0
  path: ^1.8.2
  json_annotation: ^4.8.0
  firebase_analytics: ^10.1.0
  isar: ^3.1.0+1
  isar_flutter_libs: ^3.0.2
  shared_preferences: ^2.0.17
  flutter_logs: ^2.1.10
  auth0_flutter: ^1.2.1

dev_dependencies:
  test: ^1.20.2
  integration_test:
    sdk: flutter
  flutter_test:
    sdk: flutter
  build_runner: ^2.0.3
  flutter_launcher_icons: ^0.13.1
  mockito: ^5.0.15
  corsac_jwt: ^1.0.0-nullsafety.1
  flutter_lints: ^2.0.1
  path_provider_platform_interface: ^2.0.0
  plugin_platform_interface: ^2.0.0
  # TODO once a release is made to mock server, update this to its new version
  mockserver:
    git:
      url: https://github.com/mauriciotogneri/mockserver-dart.git
      ref: 3fdf0615a5662975390ec4f96babf2663d6f9c48
  isar_generator: ^3.0.2

MilesAdamson avatar Nov 23 '23 19:11 MilesAdamson

I've narrowed down the issue a bit. In the build.grade file of the plugin, if I change the token lookup from:

rootProject.allprojects {
    def token = System.getenv("SDK_REGISTRY_TOKEN")
    if (token == null || token.empty) {
        throw new Exception("SDK Registry token is null. See README.md for more information.")
    }

to hard coding my token:

rootProject.allprojects {
    def token = "(my token hard coded here)"

It does build along with other changes to packagingOptions it did build. But it's not maintainable to edit that file all the time. Not sure what the issue actually is specifically still

MilesAdamson avatar Nov 23 '23 23:11 MilesAdamson

have you resolved this issue?

maxiggle avatar Dec 30 '23 14:12 maxiggle

No, did you have a similar issue?

MilesAdamson avatar Jan 03 '24 18:01 MilesAdamson

Having the same problem.

sunderee avatar Jan 04 '24 14:01 sunderee

hey there, I encountered this issue as well on brand new build with the most up-to-date flutter version running on my mac(intel). If needed I could provide a working example

steps:

  1. create an app using flutter CLI
  2. complete public/secret key intallation steps
  3. add native dependencies
dependencies {
    implementation 'com.mapbox.maps:android:11.0.0'
}

...

maven {
            url = uri("https://api.mapbox.com/downloads/v2/releases/maven")
            // Do not change the username below. It should always be "mapbox" (not your username).
            credentials.username = "mapbox"
            // Use the secret token stored in gradle.properties as the password
            credentials.password = providers.gradleProperty("MAPBOX_DOWNLOADS_TOKEN").get()
            authentication { basic(BasicAuthentication) }
        }
  1. add pub dependency
mapbox_maps_flutter: ^0.5.1
  1. flutter run
  2. add map widget

#output

FAILURE: Build completed with 2 failures.

**_1: Task failed with an exception.

  • Where: Build file '/Users/macbook/.pub-cache/hosted/pub.dev/mapbox_maps_flutter-0.5.1/android/build.gradle' line: 21

  • What went wrong: A problem occurred evaluating project ':mapbox_maps_flutter'.

SDK Registry token is null. See README.md for more information.

  • 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. ==============================================================================

2: Task failed with an exception.

  • What went wrong: A problem occurred configuring project ':mapbox_maps_flutter'.

Failed to notify project evaluation listener. Could not get unknown property 'android' for project ':mapbox_maps_flutter' of type org.gradle.api.Project. Could not find method implementation() for arguments [project ':flutter_plugin_android_lifecycle'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. Could not get unknown property 'android' for project ':mapbox_maps_flutter' of type org.gradle.api.Project.

  • 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. ==============================================================================_**

Wentris71 avatar Jan 04 '24 15:01 Wentris71

For me, the answer was just to set SDK_REGISTRY_TOKEN with the private mapbox token in my gradle.properties file

martinfrouin avatar Feb 27 '24 15:02 martinfrouin

In my case i followed the documentation and provided my secret key as MAPBOX_DOWNLOADS_TOKEN in gradle.property, I changed it with SDK_REGISTRY_TOKEN and the issue is resolved.

Hani24 avatar Mar 14 '24 09:03 Hani24

I don't know if it can help. But even if I created ~/.gradle/gradle.properties with SDK_REGISTRY_TOKEN=sk.... , I had always this bug when I tried to compile my app for Android platform. I remove Android folder from my flutter project and after I create a new one with the command flutter create --platforms=android . and I compile and it works fine now. Just one thing, don't forget to save your manifest.xml because after the command below, you'll have a new manifest.xml and you have to set up again every permissions,... 🥲

May be I had this bug, because one time Android Studio asks me for updating my Android project ( Android part of my flutter project) with AGP Upgrade Assistant and I said yes and some updates had created some conflicts with Flutter build.

ande4485 avatar Mar 14 '24 23:03 ande4485

In my case i followed the documentation and provided my secret key as MAPBOX_DOWNLOADS_TOKEN in gradle.property, I changed it with SDK_REGISTRY_TOKEN and the issue is resolved.

As well as in this line: credentials.password = providers.gradleProperty("MAPBOX_DOWNLOADS_TOKEN").get() to credentials.password = providers.gradleProperty("SDK_REGISTRY_TOKEN").get()

manulgdc avatar Mar 25 '24 10:03 manulgdc