# Install and set up

> Canonical URL: https://docs.mountaya.com/en/sdks/kotlin/install/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Add the Mountaya Kotlin modules from Maven Central, set up Compose and Kotlin Multiplatform, and give the app its key.

The modules are on Maven Central under `com.mountaya`, at one version. Add the ones your build uses.

## Install the packages

An Android app that shows a map adds the client and the elements:

```kotlin
dependencies {
    implementation("com.mountaya:mountaya-client:0.1.0")
    implementation("com.mountaya:mountaya-elements:0.1.0")
    // Turn-by-turn navigation, Android only.
    implementation("com.mountaya:mountaya-navigation:0.1.0")
}
```

A JVM server adds the admin package, which brings the client with it:

```kotlin
dependencies {
    implementation("com.mountaya:mountaya-admin:0.1.0")
}
```

Keep `mavenCentral()` among the build's repositories. `mountaya-geo` comes with `mountaya-elements`; add it alone for the rules without a map.

- Every module is published at the same version, and each names its siblings at exactly that version: depend on all of them at `0.1.0`, never at two versions.
- `mountaya-elements` depends on `mountaya-geo` and `mountaya-client`; `mountaya-geo` depends on `mountaya-client` with `api`; `mountaya-admin` depends on `mountaya-client`; `mountaya-navigation` depends on `mountaya-geo`. Declaring the one you call is enough, but declaring the client beside it states what you use.
- An app that draws a map, edits an itinerary, queries the Data API or navigates never declares `mountaya-admin`.
- MapLibre Native Android is a range, `[13.7.1,14.0)`, which your build may resolve to another release inside it. Never strict.

## Set up the platform

On Android, apply the Compose compiler plugin and meet the floors:

```kotlin
plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig {
        minSdk = 24
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
}
```

Declare the network in `AndroidManifest.xml`, and the location permissions if the app locates the reader or navigates:

```xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
```

In a Kotlin Multiplatform project, the four multiplatform modules go in `commonMain`, and navigation in `androidMain`:

```kotlin
kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("com.mountaya:mountaya-client:0.1.0")
            implementation("com.mountaya:mountaya-geo:0.1.0")
            implementation("com.mountaya:mountaya-elements:0.1.0")
        }
        androidMain.dependencies {
            implementation("com.mountaya:mountaya-navigation:0.1.0")
        }
    }
}
```

- Targets: `mountaya-client`, `mountaya-admin`, `mountaya-geo` and `mountaya-elements` publish `jvm`, Android, `iosArm64` and `iosSimulatorArm64`. `mountaya-navigation` publishes Android alone. There is no JS, Wasm, macOS or Linux native target.
- On iOS and on the jvm, `mountaya-elements` holds `MapEngine` and no renderer: `MapView`, the controls, the panels, `SearchControl` and the data elements are Android only. An iOS app draws the map's state with views of its own, or uses the Swift SDK.
- The Compose compiler plugin is the one of your Kotlin release (`org.jetbrains.kotlin.plugin.compose`, Kotlin 2.4 or newer). `mountaya-elements` brings Compose's UI runtime and MapLibre; it does not hand on Compose's foundation, so an app that lays out `Box`, `Column` or `BasicText` of its own declares `androidx.compose.foundation:foundation`, or Material, which brings it. An activity's `setContent` comes from `androidx.activity:activity-compose`.
- No module declares a location permission and none asks for one: the app declares `ACCESS_FINE_LOCATION` beside `ACCESS_COARSE_LOCATION` (Android 12 asks for both together) and asks in its own flow. A position is read under the full one alone. Navigating with the screen off also needs `ACCESS_BACKGROUND_LOCATION` or a foreground service of type `location` that your app runs.
- `mountaya-navigation` merges the `TTS_SERVICE` query into the app's manifest, so `SpeechNavigationVoice` finds the platform's speech engine on Android 11 and later with nothing of your own.
- No module asks for core library desugaring.

## Add your key

Keep the publishable key out of source control. Put it in an `.env` file beside the app's build script, listed in `.gitignore`:

```text
MOUNTAYA_PUBLISHABLE_KEY=pk_your_publishable_key
MOUNTAYA_SESSION_URL=http://10.0.2.2:8787/session
```

Read it in Gradle from the environment, else from `.env`, the way the SDK's sample app Trail does, into `BuildConfig`:

```kotlin
val dotEnv =
    file(".env").takeIf { it.isFile }?.readLines().orEmpty()
        .filter { "=" in it && !it.startsWith("#") }
        .associate { it.substringBefore('=').trim() to it.substringAfter('=').trim() }

fun setting(name: String): String = System.getenv(name) ?: dotEnv[name].orEmpty()

android {
    buildFeatures { buildConfig = true }
    defaultConfig {
        buildConfigField("String", "MOUNTAYA_PUBLISHABLE_KEY", "\"${setting("MOUNTAYA_PUBLISHABLE_KEY")}\"")
        buildConfigField("String", "MOUNTAYA_SESSION_URL", "\"${setting("MOUNTAYA_SESSION_URL")}\"")
    }
}
```

The app then builds its client from `BuildConfig`:

```kotlin
import com.mountaya.client.Credential
import com.mountaya.client.Mountaya

fun appClient(): Mountaya = Mountaya(Credential.Publishable(BuildConfig.MOUNTAYA_PUBLISHABLE_KEY))
```

A server reads its keys from environment variables:

```kotlin
import com.mountaya.client.Credential
import com.mountaya.client.Mountaya
import com.mountaya.client.invoke

val server = Mountaya(Credential.Secret(System.getenv("MOUNTAYA_SECRET_KEY").orEmpty()))
println(server.baseUrls)
server.close()
```

Create keys under **Organization → API keys** in the [Mountaya app](https://app.mountaya.com/api-keys).

- `.env` holds one setting a line and is listed in `.gitignore`. A variable of the same name in the shell wins over the file. `MOUNTAYA_SESSION_URL` is your server's `POST /session` (the Android emulator reaches your computer's `127.0.0.1:8787` at `10.0.2.2:8787`); see [the server quickstart](https://docs.mountaya.com/en/sdks/kotlin/quickstart-server.md#serve).
- Trail, the SDK's sample app (`examples/trail`), reads the same settings the same way (environment first, then `.env`) and hands them to the app as string resources (`resValue`) it reads with `getString`, so R8 cannot fold them into its size measurement. `BuildConfig` is the usual form for an app of your own; both keep the key out of the code.
- A publishable key (`pk_` and 32 lowercase hex characters) is the only key an app carries. The client refuses an empty key, a wrong prefix, a secret key in its place, and a character no HTTP header carries (such as the `…` of a placeholder) with a `ConfigurationException` where it is built.
- The scopes Trail's key needs: `tiles` draws the map, `publishing` reads a published itinerary, `data` searches. A key that ships in an app never carries `management`.
- The secret key (`sk_`) belongs on a server: `Credential.Secret(key)` reads as a constructor once `com.mountaya.client.invoke` is imported, and `Credential(secretKey = ...)` builds it from parts. Both are declared on the jvm alone, so an Android or iOS build cannot name them.

## Import the right package

Each module's API is one package named after it. Import the names you use:

| Module | Package | Main names |
| --- | --- | --- |
| `mountaya-client` | `com.mountaya.client` | `Mountaya`, `Credential`, `SessionTokenEngine`, the exceptions |
| `mountaya-admin` | `com.mountaya.admin` | `admin`, `constructWebhookEvent` |
| `mountaya-geo` | `com.mountaya.geo` | `formatDistance`, `SearchEngine`, `RouteFollowingEngine` |
| `mountaya-navigation` | `com.mountaya.navigation` | `DeviceNavigationEngine`, `SpeechNavigationVoice` |
| `mountaya-elements` | `com.mountaya.elements` | `MapEngine`, `MapView`, `MapControls`, `ItineraryProfile` |

The secret key and the admin package are for servers only. An app imports neither.

- Types printed from the contract live beside each package: `com.mountaya.client.generated` (`RestSchema`, `DataSchema`, `TileSchema`, `ApiErrorCode`, `SCHEMA_VERSION`, `MODEL_DIGEST`), `com.mountaya.admin.generated` (`AdminSchema`, `WebhookEvent`) and `com.mountaya.geo.generated` (`ElementTokens`, the words and the glyph sets).
- `import com.mountaya.admin.admin` declares `Mountaya.admin`, the admin unit's operations; without that import, `mountaya.admin` does not resolve. `WebhookSignatureException` is common code in `com.mountaya.admin`; `constructWebhookEvent` is declared on the jvm alone.
- `import com.mountaya.client.*` brings every name the client publishes except the printed types. The SDK's own samples import each name, as a formatter that refuses wildcard imports asks.

## Next steps

- [Quickstart](https://docs.mountaya.com/en/sdks/kotlin/quickstart.md): A map with an itinerary in a Compose app.
- [Server quickstart](https://docs.mountaya.com/en/sdks/kotlin/quickstart-server.md): Mint a session token and call the Data API on the JVM.
