Gradle 实施失败 com.mapbox.maps:android:10.2.0

Gradle Fails to implement com.mapbox.maps:android:10.2.0

我需要在我的应用程序代码中导入 import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions;,为此我需要在 build.gradle 模块中实现 com.mapbox.maps:android:10.2.0,但它失败了。

谁能告诉我,为什么这个gradle工具无法解析?

 implementation ('com.mapbox.maps:android:10.2.0'){
        exclude group: 'group_name', module: 'module_name'
    }

这是错误消息:

Failed to resolve: com.mapbox.maps:android:10.2.0

在堆栈跟踪中显示:NotFound com.mapbox.maps:android:10.2.0

在项目结构对话框中显示 受影响的模块:app

build.gradle(项目)

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
        maven {
            url 'https://api.mapbox.com/downloads/v2/releases/maven'
            authentication{
                basic(BasicAuthentication)

            }
            credentials{
                username='mapbox'
                password= project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?:""
            }

        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}


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

错误信息

经过几个小时的研究,我发现了如何在 Android

上正确设置 Mapbox (10.0.2)

IMO,第一个项目符号应该可以解决问题,否则请继续。

首先,在settings.gradle中->如前所述将模式设置为PREFERS.SETTINGS .

dependencyResolutionManagement {
  repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
  repositories {
    google()
    mavenCentral()
    jcenter() // Warning: this repository is going to shut down soon
    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 = MAPBOX_DOWNLOADS_TOKEN
        }
      }
    }
  }

其次,按照惯例添加依赖到module-level build.gradle(不是项目级别)

    implementation 'com.mapbox.maps:android:10.2.0'

第三,这是我的project-levelbuild.gradle的样子

 buildscript {
ext {
    compose_version = '1.2.0-alpha02'
}
repositories {
    google()
    mavenCentral()

}
dependencies {
    classpath 'com.android.tools.build:gradle:7.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

最后,在你的 gradle.property 中确保你有

(GOOD)   MAPBOX_DOWNLOADS_TOKEN = SECRET_ACCESS_CODE
(DO NOT) MAPBOX_DOWNLOADS_TOKEN = "SECRET_ACCESS_CODE"