【问题标题】:Can't pass token from gradle.properties to settings.gradle无法将令牌从 gradle.properties 传递给 settings.gradle
【发布时间】:2022-01-19 02:08:29
【问题描述】:

我按照https://docs.mapbox.com/android/maps/guides/install/ 的指南进行操作,除了我无法选择存储在gradle.properties 中的令牌来在settings.gradle 的 Mapbox Maven 存储库中验证我自己之外,一切似乎都正常。 安装指南中显示的方法对我不起作用。

这是我的settings.gradle

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    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 = System.getenv("MAPBOX_DOWNLOADS_TOKEN")
            }
        }
        jcenter() // Warning: this repository is going to shut down soon
    }
}
rootProject.name = "MyApp Name"
include ':app'

这是我的gradle.properties

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
MAPBOX_DOWNLOADS_TOKEN=this_is_my_secret_access_token

我做错了什么?

【问题讨论】:

    标签: android android-studio gradle mapbox mapbox-android


    【解决方案1】:

    阅读 gradle 文档后,我发现 mapbox 安装指南做错的事情是在gradle.properties 中设置了 token 变量。 您需要将其指定为系统属性(请参阅https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_system_properties),因此基本上您所要做的就是更改

    MAPBOX_DOWNLOADS_TOKEN=this_is_my_secret_access_token
    

    systemProp.MAPBOX_DOWNLOADS_TOKEN=this_is_my_secret_access_token
    

    现在移动到settings.gradle 文件并更改行

    password = System.getenv("MAPBOX_DOWNLOADS_TOKEN")
    

    password = System.properties["MAPBOX_DOWNLOADS_TOKEN"]
    

    【讨论】:

      猜你喜欢
      • 2017-10-03
      • 2016-06-22
      • 1970-01-01
      • 2018-10-23
      • 2017-01-16
      • 2019-09-21
      • 2023-04-02
      • 1970-01-01
      • 2018-01-05
      相关资源
      最近更新 更多