Mapbox SDK Registry Token 为空

Mapbox SDK Registry Token is null

我在我的 flutter 应用程序上安装 mapbox_gl 插件时遇到问题...

我确实遵循了那里的官方说明:

https://pub.dev/packages/mapbox_gl

但是每当我点击 flutter 运行 时,我都会收到相同的消息:

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

这导致:

Could not get unknown property 'android' for project ':mapbox_gl' of type org.gradle.api.Project.

看起来像一个 gradle 问题...我错过了什么?

我正在使用 beta flutter 频道和 运行 --no-sound-null-safety

这是我的代码:

android/build.graddle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    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 = "[Yes I checked this token multiple times]"
            }
        }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

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

android/app/build.graddle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.mobile_coring"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    // Add the block below if you're using Kotlin
    kotlinOptions {
        jvmTarget = "1.8"
    }

}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.1'
}

pubspec.yaml

description: A new Flutter project.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  flutter_login: ^1.1.0
  percent_indicator: ^3.0.1
  location: ^4.1.1
  mapbox_gl: ^0.12.0

dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  assets:
  - assets/images/maorie.png
  - assets/images/tiro.png
  - assets/images/coccinelle.jpg

  fonts:
    - family: Cabin
      fonts:
        - asset: assets/fonts/Cabin-Italic.ttf
          style: italic
        - asset: assets/fonts/Cabin-SemiBold.ttf
          weight: 600
        - asset: assets/fonts/Cabin-SemiBoldItalic.ttf
          weight: 600
          style: italic
        - asset: assets/fonts/Cabin-Bold.ttf
          weight: 700
        - asset: assets/fonts/Cabin-BoldItalic.ttf
          weight: 700
          style: italic

  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

我在安装这个插件时也遇到了问题 最后,我设法导入 运行 mapbox_gl: ^0.10.0 只需按照以下步骤操作:

  1. 在你的android/app/build.gradle设置

compileSdkVersion 29

minSdkVersion 20

targetSdkVersion 29

  1. 在android/build.gradle设置
buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
  1. 在android/gradle/wrapper/gradle_wrapper.properties中设置

distributionUrl=https://services.gradle.org/distributions/gradle-5.6.2-all.zip

  1. 终于在你的pubspec.yaml导入

mapbox_gl: ^0.10.0

我遇到了同样的问题,然后这样解决:

  1. 删除 mapbox_gl 包并在 pubspec.yaml
  2. 上安装 flutter_map
  3. 在位于 <project root>/android/app/src/main/AndroidManiFest.xml
  4. 的清单文件中将您的应用配置为使用互联网权限
<uses-permission android:name="android.permission.INTERNET"/>
  1. 现在我们可以使用 FlutterMap() 小部件,但您需要在 mapbox 上创建一个帐户并复制“默认 public 令牌”

  2. 然后在“工具和资源”部分单击“在 Mapbox Studio 中设计”,如 here,然后在打开的新页面单击“新样式”

  3. 在这里你可以选择任何你想要的风格this

  4. 首先点击“分享您的风格”图标(参见 here) and go to "Third party" tab and chose "CARTO" then copy the "Integration URL" like here

  5. 现在我们需要转到“Tilesets”page and copy the ID of Tilesets like here

  6. 让我们使用FlutterMap()

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart' as latLng;

class MapScreen extends StatefulWidget {

  @override
  _MapScreenState createState() => _MapScreenState();
}

class _MapScreenState extends State<MapScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Chose From Map'),
      ),
      body: FlutterMap(
        options: MapOptions(
          center: latLng.LatLng(51.5, -0.09),
          zoom: 13.0,
        ),
        layers: [
          TileLayerOptions(
            urlTemplate: 'use Integration URL here',
            additionalOptions: {'accessToken': 'use Default public token here',
              'id': 'use the ID of Tilesets here',
            },
          ),
        ],
      ),
    );
  }
}
  1. 现在 运行 你的应用程序。

将此行添加到您的 gradle.properties 文件中:

MAPBOX_DOWNLOADS_TOKEN=YOUR MAPBOX DOWNLOADS ACCESS TOKEN

按照此文档创建您的令牌: https://docs.mapbox.com/android/maps/guides/install/