mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
475 stars 133 forks source link

install mapbox on java android studio project #2146

Closed samuele-lolli closed 1 year ago

samuele-lolli commented 1 year ago

I'm developing an android application with java and I want to integrate Mapbox, I followed all the documentation here: https://docs.mapbox.com/android/maps/guides/install/

I requested both tokens successfully and added the dependency in the build.gradle.kts:

dependencies {
    implementation ("com.mapbox.maps:android:10.15.0")
}

The problem is when I insert the following code into settings.gradle.kts:

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 = MAPBOX_DOWNLOADS_TOKEN
            }
        }
    }
}

url and basic are not recognized by android studio and I get several errors, in particular:

I used Java for the project but the gradle files have the kts extensione because when i create the project i select the java language but build with kotlin.

pvtan commented 1 year ago

If using kts, you can set it up like this

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://api.mapbox.com/downloads/v2/releases/maven")
            authentication {
                create<BasicAuthentication>("basic")
            }
            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
            }
        }
    }
}
samuele-lolli commented 1 year ago

thank you!