【问题标题】:Failed to resolve: com.mapbox.maps:android:10.0.0无法解决:com.mapbox.maps:android:10.0.0
【发布时间】:2021-11-08 09:53:05
【问题描述】:

我在 Android Studio 上建立了一个新项目,我正在尝试使用 Mapbox SDK v10。但是,我的 Gradle 构建失败并显示以下消息:

无法解析:com.mapbox.maps:android:10.0.0。

有人可以帮帮我吗?如何正确导入 Mapbox 的 v10 实现?提前致谢!

这是我的根级 build.gradle:

buildscript {
    repositories {
        google()
        mavenCentral()
        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 = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
            }
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
        classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        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 = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
            }
        }
    }
}

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

这是我的项目级 build.gradle:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "--------" //This is my application's ID, I've removed it for security purposes
        minSdkVersion 21
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        resValue "string", "mapTilerKey", "udm4bYUze4mksls7yU8o"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation 'com.mapbox.maps:android:10.0.0'
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'org.maplibre.gl:android-sdk:9.2.1'
    implementation 'com.google.android.gms:play-services-location:18.0.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

【问题讨论】:

  • 如果您已经按照indicated in their documentation 的步骤操作(并且您没有犯错/错字),那么您可能遇到了连接问题。
  • 我已经对所有文件以及我的连接进行了四次检查,以确定是否存在任何连接问题。我不明白出了什么问题。我什至从头开始,完全按照文档中的安装说明进行操作,但我仍然遇到这个问题。会发生什么?
  • 很高兴听到您找到了解决方案! :)

标签: android android-studio mapbox mapbox-android


【解决方案1】:

最后我想通了。在settings.gradle,我改了这一行

repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

到

repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

所以项目级别的build.gradle 文件没有被考虑在内,正在考虑的回购来自settings.gradle。只需将settings.gradle 更改为:

repositories {
    google()
    mavenCentral()
    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 = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
        }
    }
}

【讨论】:

  • 请您提供完整的工作示例(一些回购),我还没有提出解决方案。尽管我在很长一段时间内基本上都在做同样的事情
【解决方案2】:

经过几个小时的研究,我开始了解如何正确设置 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
        }
      }
    }
  }

其次,像往常一样将依赖添加到模块级别 build.gradle(不是项目级别)

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

第三,这就是我的项目级 build.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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 2016-03-30
    相关资源
    最近更新 更多