admin管理员组

文章数量:1392081

I'm trying to set up the Mapbox SDK for use in Android Studio, which requires authentication setup. In every example I can find, it's supposed to be set up approximately like this in the dependencyResolutionManagement block in settings.gradle:

maven {
    url = uri("URL HERE")
    authentication {
        basic(BasicAuthentication)
    }
    credentials {
        username = "mapbox"
        password = "" // private token here.
    }
}

This is just giving a build error and the authentication basic(BasicAuthentication) seems to be the problem. This call is in every example I can find, but the basic() function seems to be returning the wrong type, and anyways I cannot for the life of me find the docs for that function, including what package it's in so that I can import the correct one.

Since every examples gives this code, I have tried to build the project using the setup with basic(), but I'm getting the error message:

Classifier 'BasicAuthentication' does not have a companion object, and thus must be initialized here

This seems to result from basic() being defined as returning a "SafeList" object, which seems completely wrong as the parameter of the authentication() method is to be an Action object. So I can't "find" or import the correct basic() function.

I'm trying to set up the Mapbox SDK for use in Android Studio, which requires authentication setup. In every example I can find, it's supposed to be set up approximately like this in the dependencyResolutionManagement block in settings.gradle:

maven {
    url = uri("URL HERE")
    authentication {
        basic(BasicAuthentication)
    }
    credentials {
        username = "mapbox"
        password = "" // private token here.
    }
}

This is just giving a build error and the authentication basic(BasicAuthentication) seems to be the problem. This call is in every example I can find, but the basic() function seems to be returning the wrong type, and anyways I cannot for the life of me find the docs for that function, including what package it's in so that I can import the correct one.

Since every examples gives this code, I have tried to build the project using the setup with basic(), but I'm getting the error message:

Classifier 'BasicAuthentication' does not have a companion object, and thus must be initialized here

This seems to result from basic() being defined as returning a "SafeList" object, which seems completely wrong as the parameter of the authentication() method is to be an Action object. So I can't "find" or import the correct basic() function.

Share Improve this question asked Mar 11 at 16:59 heisveisheisveis 111 silver badge4 bronze badges 2
  • 1 Could you please confirm that you are editing settings.gradle (Groovy syntax) and not settings.gradle.kts (Kotlin syntax)? – CommonsWare Commented Mar 11 at 17:05
  • @CommonsWare You're right, at about the same time as you commented I found out that every guide I had looked at assumed Groovy for build config, while I'm using Kotlin. So yeah. When I updated it accordingly, it seemed to work - posting an answer about this. Thank you! – heisveis Commented Mar 12 at 16:31
Add a comment  | 

2 Answers 2

Reset to default 1

So I found out that every guide I looked at, assumed that Gradle setup was done with Groovy (in settings.gradle), while I was using Kotlin (hence editing settings.gradle.kts), and did not realize this. To update the auth setup accordingly with the correct syntax for Kotlin:

dependencyResolutionManagement {
    repositories {
        maven(url = uri("URL HERE")) {
            credentials {
                username = "username"
                password = "" // private token here.
            }
            authentication.create<BasicAuthentication>("basic")
        }
    }
}

From your description you are missing a repositories block. It should look like this:

dependencyResolutionManagement {
    repositories {
        maven {
            url = uri("URL HERE")
            authentication {
                basic(BasicAuthentication)
            }
            credentials {
                username = "mapbox"
                password = "" // private token here.
            }
        }
    }
}

Here, basic is not a regular function but the name a of domain object of type BasicAuthentication you are creating inside the AuthenticationContainer. You should be able to call it whatever you like.

本文标签: