Learn how to create and display a mapA map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more with a basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more .

Responsive devices displaying a topographic coastal map.

A map contains layersA layer is a reference to a collection of geographic data that is used to access and display data. The data for layers are typically provided by the basemap layer service and data services. Learn more of geographic data. A map contains a basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more and, optionally, one or more data layersA data layer is a layer that references geographic data from a file or a service and is used to visualize the data in a map or scene. Learn more . You can display a specific area of a map by using a map viewA map view is a user interface that displays map layers and graphics in 2D. It controls the area (extent) of the map that is visible and supports user interactions such as pan and zoom. Learn more and setting the locationA location is a position or region (point, line, or polygon) on the earth's surface. Learn more and zoom levelZoom level is a value that sets the scale for a map view or a scene view. Learn more .

In this tutorial, you create and display a mapA map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more of the Santa Monica Mountains in California using the topographic basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more .

The map and code will be used as the starting point for other 2D tutorials.

Prerequisites

Before starting this tutorial, you need the following:

  1. An ArcGIS Location Platform or ArcGIS Online account.

  2. A development and deployment environment that meets the system requirements.

  3. An IDE for Android development in Kotlin.

Set up authentication

To access the secure ArcGIS location servicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Static Maps service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more used in this tutorial, you must implement API key authenticationAPI key authentication is a type of authentication that uses an API key to authenticate requests to ArcGIS services and secure portal items. Learn more or user authenticationUser authentication is a type of authentication that allows users with an ArcGIS account to sign into an application and allow it to access ArcGIS content, services, and resources on their behalf. The typical authorization protocol used is OAuth2.0. Learn more using an ArcGIS Location PlatformAn ArcGIS Location Platform account, formerly known as an ArcGIS Developer account, is an identity associated with an ArcGIS Location Platform subscription. Learn more or an ArcGIS OnlineAn ArcGIS Online account, also known as an ArcGIS Organization account, is an identity associated with an ArcGIS Online subscription. It can be used to access ArcGIS tools and develop applications with ArcGIS location services for an organization. Learn more account.

To complete this tutorial, click on the tab in the switcher below for your authentication type of choice, either API key authentication or User authentication.

Create a new API key access tokenAn access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. Learn more with privilegesPrivileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more to access the secure resources used in this tutorial.

  1. Complete the Create an API key tutorial and create an API key with the following privilege(s)Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more :

    • Privileges
      • Location services > Basemaps
  2. Copy and paste the API key access token into a safe location. It will be used in a later step.

Develop or download

You have two options for completing this tutorial:

  1. Option 1: Develop the code or
  2. Option 2: Download the completed solution

Option 1: Develop the code

Create a new Android Studio project

Use Android Studio to create an app and configure it to reference the API.

  1. Open Android Studio.

    • In the Welcome to Android Studio window, click New Project.

      Or if you already have Android Studio opened, click File > New > New Project in the menu bar.

    • In the New Project window, make sure Phone and Tablet tab is selected, and then select Empty Activity. Click Next.

    • In the next window, set the following options and then click Finish.

      • Name: Tutorial.
      • Package name: Change to com.example.app. Or change to match your organization.
      • Save location: Set to a new folder.
      • Minimum SDK: API 28 (“Pie”; Android 9.0)
      • Build configuration language: Kotlin DSL (build.gradle.kts)
  2. In the Project tool window, make sure that your current view is Android. These tutorial instructions refer to that view.

  3. From the Android view, open Gradle Scripts > build.gradle.kts (Project: Tutorial). Replace the contents of the file with the following code.

    build.gradle.kts (Project: Tutorial)
    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.kotlin.compose) apply false
    }
    • From the Android view, open Gradle Scripts > build.gradle.kts (Module :app). Replace the contents of the file with the entire expanded code below.

      build.gradle.kts (Module: app)
      56 collapsed lines
      plugins {
      alias(libs.plugins.android.application)
      alias(libs.plugins.kotlin.compose)
      }
      android {
      namespace = "com.example.app"
      compileSdk {
      version = release(libs.versions.compileSdk.get().toInt())
      }
      defaultConfig {
      applicationId = "com.example.app"
      minSdk = libs.versions.minSdk.get().toInt()
      targetSdk = libs.versions.targetSdk.get().toInt()
      versionCode = 1
      versionName = "1.0"
      testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
      vectorDrawables {
      useSupportLibrary = true
      }
      }
      buildTypes {
      release {
      isMinifyEnabled = false
      proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
      }
      }
      compileOptions {
      sourceCompatibility = JavaVersion.VERSION_17
      targetCompatibility = JavaVersion.VERSION_17
      }
      buildFeatures {
      compose = true
      }
      }
      dependencies {
      implementation(libs.androidx.core.ktx)
      implementation(libs.androidx.lifecycle.runtime.ktx)
      implementation(libs.androidx.activity.compose)
      implementation(platform(libs.androidx.compose.bom))
      implementation(libs.androidx.ui)
      implementation(libs.androidx.ui.graphics)
      implementation(libs.androidx.ui.tooling.preview)
      implementation(libs.androidx.material3)
      testImplementation(libs.junit)
      androidTestImplementation(libs.androidx.junit)
      androidTestImplementation(libs.androidx.espresso.core)
      androidTestImplementation(platform(libs.androidx.compose.bom))
      androidTestImplementation(libs.androidx.ui.test.junit4)
      debugImplementation(libs.androidx.ui.tooling)
      debugImplementation(libs.androidx.ui.test.manifest)
      // ArcGIS Maps for Kotlin - SDK dependency
      implementation(libs.arcgis.maps.kotlin)
      implementation(platform(libs.arcgis.maps.kotlin.toolkit.bom))
      implementation(libs.arcgis.maps.kotlin.toolkit.geoview.compose)
      implementation(libs.arcgis.maps.kotlin.toolkit.authentication)
      2 collapsed lines
      }
      • From the Android view, open Gradle Scripts > libs.versions.toml. In the [versions] section, you need to declare the version number for ArcGIS Maps SDK for Kotlin. And in the [libraries] section, you need to add the library declarations for the following:

        • arcgis-maps-kotlin
        • arcgis-maps-kotlin-toolkit-bom
        • arcgis-maps-kotlin-toolkit-geoview-compose
        • arcgis-maps-kotlin-toolkit-authentication

        The version for the Toolkit BOM applies to all the Toolkit modules you declare.

        Expand the code below, copy the entire expanded contents, and paste it into libs.version.toml file, replacing the original contents generated by the New Project Wizard.

        gradle/libs.versions.toml
        [versions]
        arcgisMapsKotlin = "300.1.0"
        # Version numbers added by Android Studio New Project Wizard
        agp = "9.2.1"
        39 collapsed lines
        kotlin = "2.3.21"
        coreKtx = "1.18.0"
        junit = "4.13.2"
        junitVersion = "1.3.0"
        espressoCore = "3.7.0"
        lifecycleRuntimeKtx = "2.9.2"
        activityCompose = "1.13.0"
        composeBom = "2026.04.01"
        # Other version numbers
        compileSdk = "37"
        minSdk = "28"
        targetSdk = "37"
        [libraries]
        arcgis-maps-kotlin = { group = "com.esri", name = "arcgis-maps-kotlin", version.ref = "arcgisMapsKotlin" }
        arcgis-maps-kotlin-toolkit-bom = { group = "com.esri", name = "arcgis-maps-kotlin-toolkit-bom", version.ref = "arcgisMapsKotlin" }
        arcgis-maps-kotlin-toolkit-geoview-compose = { group = "com.esri", name = "arcgis-maps-kotlin-toolkit-geoview-compose" }
        arcgis-maps-kotlin-toolkit-authentication = { group = "com.esri", name = "arcgis-maps-kotlin-toolkit-authentication" }
        androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
        junit = { group = "junit", name = "junit", version.ref = "junit" }
        androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
        androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
        androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
        androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
        androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
        androidx-ui = { group = "androidx.compose.ui", name = "ui" }
        androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
        androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
        androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
        androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
        androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
        androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
        [plugins]
        android-application = { id = "com.android.application", version.ref = "agp" }
        kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
        • From the Android view, open Gradle Scripts > settings.gradle.kts. Replace the contents of the file with the expanded code below.

          settings.gradle.kts (Tutorial)
          15 collapsed lines
          pluginManagement {
          repositories {
          google {
          content {
          includeGroupByRegex("com\\.android.*")
          includeGroupByRegex("com\\.google.*")
          includeGroupByRegex("androidx.*")
          }
          }
          mavenCentral()
          gradlePluginPortal()
          }
          }
          dependencyResolutionManagement {
          repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
          repositories {
          google()
          mavenCentral()
          maven { url = uri("https://esri.jfrog.io/artifactory/arcgis") }
          }
          }
          rootProject.name = "Tutorial"
          include(":app")
          • Sync the Gradle changes. Click the Sync now prompt or click the refresh icon (Sync Project with Gradle Files) in the toolbar. This may take several minutes.

          • From the Android view, open app > manifests > AndroidManifest.xml. Update the Android manifest to allow internet access.

            AndroidManifest.xml
            2 collapsed lines
            <?xml version="1.0" encoding="utf-8"?>
            <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools">
            <uses-permission android:name="android.permission.INTERNET" />
            25 collapsed lines
            <application
            android:allowBackup="true"
            android:dataExtractionRules="@xml/data_extraction_rules"
            android:fullBackupContent="@xml/backup_rules"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/Theme.Tutorial"
            tools:targetApi="31">
            <activity
            android:name=".MainActivity"
            android:exported="true"
            android:theme="@style/Theme.Tutorial">
            <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            </activity>
            </application>
            </manifest>

            Create a map

            1. From the Android view, right click on app > kotlin+java > com.example.app, select New > package from the list. Enter com.example.app.screens as the package name. Hit Enter on your keyboard. This step creates a new package that will contain the UI files.

            2. Right click on the screens package you just created, select New > Kotlin Class/File from the list. In the pop-up window, select File and enter MainScreen as the file name. Hit Enter on your keyboard.

            3. In MainScreen.kt, delete any lines of code that were inserted automatically by Android Studio. Then add the following OptIn annotation, package name, and imports.

              MainScreen.kt
              @file:OptIn(ExperimentalMaterial3Api::class)
              package com.example.app.screens
              import androidx.compose.foundation.layout.fillMaxSize
              import androidx.compose.foundation.layout.padding
              import androidx.compose.material3.ExperimentalMaterial3Api
              import androidx.compose.material3.Scaffold
              import androidx.compose.material3.Text
              import androidx.compose.material3.TopAppBar
              import androidx.compose.runtime.Composable
              import androidx.compose.runtime.remember
              import androidx.compose.ui.Modifier
              import androidx.compose.ui.res.stringResource
              import com.arcgismaps.mapping.ArcGISMap
              import com.arcgismaps.mapping.BasemapStyle
              import com.arcgismaps.mapping.Viewpoint
              import com.arcgismaps.toolkit.geoviewcompose.MapView
              import com.example.app.R
              • Create a top-level function named createMap() that returns an ArcGISMap.

                MainScreen.kt
                20 collapsed lines
                @file:OptIn(ExperimentalMaterial3Api::class)
                package com.example.app.screens
                import androidx.compose.foundation.layout.fillMaxSize
                import androidx.compose.foundation.layout.padding
                import androidx.compose.material3.ExperimentalMaterial3Api
                import androidx.compose.material3.Scaffold
                import androidx.compose.material3.Text
                import androidx.compose.material3.TopAppBar
                import androidx.compose.runtime.Composable
                import androidx.compose.runtime.remember
                import androidx.compose.ui.Modifier
                import androidx.compose.ui.res.stringResource
                import com.arcgismaps.mapping.ArcGISMap
                import com.arcgismaps.mapping.BasemapStyle
                import com.arcgismaps.mapping.Viewpoint
                import com.arcgismaps.toolkit.geoviewcompose.MapView
                import com.example.app.R
                fun createMap(): ArcGISMap {
                }
                • Create an ArcGISMap using the BasemapStyle.ArcGISTopographic, and call apply {} on the map. The function returns this ArcGISMap.

                  MainScreen.kt
                  20 collapsed lines
                  @file:OptIn(ExperimentalMaterial3Api::class)
                  package com.example.app.screens
                  import androidx.compose.foundation.layout.fillMaxSize
                  import androidx.compose.foundation.layout.padding
                  import androidx.compose.material3.ExperimentalMaterial3Api
                  import androidx.compose.material3.Scaffold
                  import androidx.compose.material3.Text
                  import androidx.compose.material3.TopAppBar
                  import androidx.compose.runtime.Composable
                  import androidx.compose.runtime.remember
                  import androidx.compose.ui.Modifier
                  import androidx.compose.ui.res.stringResource
                  import com.arcgismaps.mapping.ArcGISMap
                  import com.arcgismaps.mapping.BasemapStyle
                  import com.arcgismaps.mapping.Viewpoint
                  import com.arcgismaps.toolkit.geoviewcompose.MapView
                  import com.example.app.R
                  fun createMap(): ArcGISMap {
                  return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
                  }
                  }
                  • In the apply block, create a Viewpoint with x (longitude) and y (latitude) coordinates, and a scale. Assign the view point to the initialViewpoint property of the ArcGISMap.

                    MainScreen.kt
                    20 collapsed lines
                    @file:OptIn(ExperimentalMaterial3Api::class)
                    package com.example.app.screens
                    import androidx.compose.foundation.layout.fillMaxSize
                    import androidx.compose.foundation.layout.padding
                    import androidx.compose.material3.ExperimentalMaterial3Api
                    import androidx.compose.material3.Scaffold
                    import androidx.compose.material3.Text
                    import androidx.compose.material3.TopAppBar
                    import androidx.compose.runtime.Composable
                    import androidx.compose.runtime.remember
                    import androidx.compose.ui.Modifier
                    import androidx.compose.ui.res.stringResource
                    import com.arcgismaps.mapping.ArcGISMap
                    import com.arcgismaps.mapping.BasemapStyle
                    import com.arcgismaps.mapping.Viewpoint
                    import com.arcgismaps.toolkit.geoviewcompose.MapView
                    import com.example.app.R
                    fun createMap(): ArcGISMap {
                    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
                    initialViewpoint = Viewpoint(
                    latitude = 34.0270,
                    longitude = -118.8050,
                    scale = 72000.0
                    )
                    }
                    }

                    Create a MainScreen to hold the map

                    1. Create a composable function named MainScreen, which will call MapView.

                      MainScreen.kt
                      20 collapsed lines
                      @file:OptIn(ExperimentalMaterial3Api::class)
                      package com.example.app.screens
                      import androidx.compose.foundation.layout.fillMaxSize
                      import androidx.compose.foundation.layout.padding
                      import androidx.compose.material3.ExperimentalMaterial3Api
                      import androidx.compose.material3.Scaffold
                      import androidx.compose.material3.Text
                      import androidx.compose.material3.TopAppBar
                      import androidx.compose.runtime.Composable
                      import androidx.compose.runtime.remember
                      import androidx.compose.ui.Modifier
                      import androidx.compose.ui.res.stringResource
                      import com.arcgismaps.mapping.ArcGISMap
                      import com.arcgismaps.mapping.BasemapStyle
                      import com.arcgismaps.mapping.Viewpoint
                      import com.arcgismaps.toolkit.geoviewcompose.MapView
                      import com.example.app.R
                      @Composable
                      fun MainScreen() {
                      }
                      16 collapsed lines
                      fun createMap(): ArcGISMap {
                      return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
                      initialViewpoint = Viewpoint(
                      latitude = 34.0270,
                      longitude = -118.8050,
                      scale = 72000.0
                      )
                      }
                      }
                      • Add a remember block and call createMap() inside it. Then assign remember to a local variable named map.

                        MainScreen.kt
                        20 collapsed lines
                        @file:OptIn(ExperimentalMaterial3Api::class)
                        package com.example.app.screens
                        import androidx.compose.foundation.layout.fillMaxSize
                        import androidx.compose.foundation.layout.padding
                        import androidx.compose.material3.ExperimentalMaterial3Api
                        import androidx.compose.material3.Scaffold
                        import androidx.compose.material3.Text
                        import androidx.compose.material3.TopAppBar
                        import androidx.compose.runtime.Composable
                        import androidx.compose.runtime.remember
                        import androidx.compose.ui.Modifier
                        import androidx.compose.ui.res.stringResource
                        import com.arcgismaps.mapping.ArcGISMap
                        import com.arcgismaps.mapping.BasemapStyle
                        import com.arcgismaps.mapping.Viewpoint
                        import com.arcgismaps.toolkit.geoviewcompose.MapView
                        import com.example.app.R
                        @Composable
                        fun MainScreen() {
                        val map = remember {
                        createMap()
                        }
                        }
                        16 collapsed lines
                        fun createMap(): ArcGISMap {
                        return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
                        initialViewpoint = Viewpoint(
                        latitude = 34.0270,
                        longitude = -118.8050,
                        scale = 72000.0
                        )
                        }
                        }
                        • You will now call several composable functions from Android Jetpack Compose. Call Scaffold and pass a TopAppBar with a Text that contains the app name (R.string.app_name).

                          MainScreen.kt
                          20 collapsed lines
                          @file:OptIn(ExperimentalMaterial3Api::class)
                          package com.example.app.screens
                          import androidx.compose.foundation.layout.fillMaxSize
                          import androidx.compose.foundation.layout.padding
                          import androidx.compose.material3.ExperimentalMaterial3Api
                          import androidx.compose.material3.Scaffold
                          import androidx.compose.material3.Text
                          import androidx.compose.material3.TopAppBar
                          import androidx.compose.runtime.Composable
                          import androidx.compose.runtime.remember
                          import androidx.compose.ui.Modifier
                          import androidx.compose.ui.res.stringResource
                          import com.arcgismaps.mapping.ArcGISMap
                          import com.arcgismaps.mapping.BasemapStyle
                          import com.arcgismaps.mapping.Viewpoint
                          import com.arcgismaps.toolkit.geoviewcompose.MapView
                          import com.example.app.R
                          @Composable
                          fun MainScreen() {
                          val map = remember {
                          createMap()
                          }
                          Scaffold(
                          topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
                          ) {
                          }
                          }
                          16 collapsed lines
                          fun createMap(): ArcGISMap {
                          return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
                          initialViewpoint = Viewpoint(
                          latitude = 34.0270,
                          longitude = -118.8050,
                          scale = 72000.0
                          )
                          }
                          }
                          • In the trailing lambda for Scaffold, call the MapView composable defined in the ArcGIS Maps SDK for Kotlin Toolkit. Pass a Modifier that has maximum size and default padding. And pass map as the arcGISMap parameter.

                            MainScreen.kt
                            20 collapsed lines
                            @file:OptIn(ExperimentalMaterial3Api::class)
                            package com.example.app.screens
                            import androidx.compose.foundation.layout.fillMaxSize
                            import androidx.compose.foundation.layout.padding
                            import androidx.compose.material3.ExperimentalMaterial3Api
                            import androidx.compose.material3.Scaffold
                            import androidx.compose.material3.Text
                            import androidx.compose.material3.TopAppBar
                            import androidx.compose.runtime.Composable
                            import androidx.compose.runtime.remember
                            import androidx.compose.ui.Modifier
                            import androidx.compose.ui.res.stringResource
                            import com.arcgismaps.mapping.ArcGISMap
                            import com.arcgismaps.mapping.BasemapStyle
                            import com.arcgismaps.mapping.Viewpoint
                            import com.arcgismaps.toolkit.geoviewcompose.MapView
                            import com.example.app.R
                            @Composable
                            fun MainScreen() {
                            val map = remember {
                            createMap()
                            }
                            Scaffold(
                            topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
                            ) {
                            MapView(
                            modifier = Modifier.fillMaxSize().padding(it),
                            arcGISMap = map
                            )
                            }
                            }
                            16 collapsed lines
                            fun createMap(): ArcGISMap {
                            return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
                            initialViewpoint = Viewpoint(
                            latitude = 34.0270,
                            longitude = -118.8050,
                            scale = 72000.0
                            )
                            }
                            }

                            Call MainScreen inside MainActivity class

                            1. Open the app > kotlin+java > com.example.app > MainActivity.kt. Delete all lines of code in the file. Then add the package declaration, import statements, and the MainActivity class.

                              MainActivity.kt
                              package com.example.app
                              import android.os.Bundle
                              import androidx.activity.ComponentActivity
                              import androidx.activity.compose.setContent
                              import androidx.activity.enableEdgeToEdge
                              import com.arcgismaps.ApiKey
                              import com.arcgismaps.ArcGISEnvironment
                              import com.arcgismaps.httpcore.authentication.OAuthUserConfiguration
                              import com.arcgismaps.toolkit.authentication.AuthenticatorState
                              import com.arcgismaps.toolkit.authentication.DialogAuthenticator
                              import com.example.app.screens.MainScreen
                              import com.example.app.ui.theme.TutorialTheme
                              class MainActivity : ComponentActivity() {
                              }
                              • In the setContent block of the onCreate() lifecycle function, you will call the composable function MainScreen, with default theming applied. To do this, add onCreate() with the following code.

                                MainActivity.kt
                                class MainActivity : ComponentActivity() {
                                override fun onCreate(savedInstanceState: Bundle?) {
                                super.onCreate(savedInstanceState)
                                enableEdgeToEdge()
                                setContent {
                                TutorialTheme {
                                MainScreen()
                                }
                                }
                                }
                                }

                                Set developer credentials

                                To allow your app users to access ArcGIS Location ServicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Static Maps service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more , use the developer credentials that you created in the Set up authentication step to authenticate requests for resources.

                                1. In the Android view of Android Studio, open app > kotlin+java > com.example.app > MainActivity.

                                2. In the onCreate() lifecycle method of the MainActivity class, set the ArcGISEnvironment.apiKey​ property by calling ApiKey.create(). Pass in your API key access token as a string and don’t forget the double quotes. Do this before the setContent block.

                                  MainActivity.kt
                                  13 collapsed lines
                                  package com.example.app
                                  import android.os.Bundle
                                  import androidx.activity.ComponentActivity
                                  import androidx.activity.compose.setContent
                                  import androidx.activity.enableEdgeToEdge
                                  import com.arcgismaps.ApiKey
                                  import com.arcgismaps.ArcGISEnvironment
                                  import com.example.app.screens.MainScreen
                                  import com.example.app.ui.theme.TutorialTheme
                                  class MainActivity : ComponentActivity() {
                                  override fun onCreate(savedInstanceState: Bundle?) {
                                  super.onCreate(savedInstanceState)
                                  ArcGISEnvironment.apiKey = ApiKey.create("YOUR_ACCESS_TOKEN")
                                  enableEdgeToEdge()
                                  setContent {
                                  TutorialTheme {
                                  MainScreen()
                                  }
                                  }
                                  }
                                  }

                                  Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

                                  Run your app

                                  1. Click Run > Run > app to run the app.

                                  You should see a mapA map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more with the topographic basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more centered on the Santa Monica Mountains in California. Pinch, drag, and double-tap the map view to explore the map.

                                  Alternatively, you can download the tutorial solution, as follows.

                                  Option 2: Download the solution

                                  1. Click the Download solution link in the right-hand side of this page.

                                  2. Unzip the file to a location on your machine.

                                  3. Run Android Studio.

                                  4. Go to File > Open…. Navigate to the solution folder and click Open.

                                    On Windows: If you are in the Welcome to Android Studio dialog, click Open and navigate to the solution folder. Then click Open.

                                  Since the downloaded solution does not contain authentication credentials, you must add the developer credentials that you created in the Set up authentication section.

                                  Set developer credentials in the solution

                                  To allow your app users to access ArcGIS location servicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Static Maps service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more , use the developer credentials that you created in the Set up authentication step to authenticate requests for resources.

                                  1. In the Android view of Android Studio, open app > kotlin+java > com.example.app > MainActivity. Set the AuthenticationMode to .API_KEY.

                                    MainActivity.kt
                                    14 collapsed lines
                                    package com.example.app
                                    import android.os.Bundle
                                    import androidx.activity.ComponentActivity
                                    import androidx.activity.compose.setContent
                                    import androidx.activity.enableEdgeToEdge
                                    import com.arcgismaps.ApiKey
                                    import com.arcgismaps.ArcGISEnvironment
                                    import com.arcgismaps.httpcore.authentication.OAuthUserConfiguration
                                    import com.arcgismaps.toolkit.authentication.AuthenticatorState
                                    import com.arcgismaps.toolkit.authentication.DialogAuthenticator
                                    import com.example.app.screens.MainScreen
                                    import com.example.app.ui.theme.TutorialTheme
                                    class MainActivity : ComponentActivity() {
                                    private enum class AuthenticationMode { API_KEY, USER_AUTH }
                                    private val authenticationMode = AuthenticationMode.API_KEY
                                    42 collapsed lines
                                    private val authenticatorState = AuthenticatorState()
                                    override fun onCreate(savedInstanceState: Bundle?) {
                                    super.onCreate(savedInstanceState)
                                    when (authenticationMode) {
                                    AuthenticationMode.API_KEY -> {
                                    ArcGISEnvironment.apiKey = ApiKey.create("YOUR_ACCESS_TOKEN")
                                    }
                                    AuthenticationMode.USER_AUTH -> {
                                    authenticatorState.oAuthUserConfigurations = listOf(
                                    OAuthUserConfiguration(
                                    portalUrl = "https://www.arcgis.com",
                                    clientId = "YOUR_CLIENT_ID",
                                    redirectUrl = "YOUR_REDIRECT_URL"
                                    )
                                    )
                                    }
                                    }
                                    enableEdgeToEdge()
                                    setContent {
                                    TutorialTheme {
                                    MainScreen()
                                    if (authenticationMode == AuthenticationMode.USER_AUTH) {
                                    DialogAuthenticator(authenticatorState)
                                    }
                                    }
                                    }
                                    }
                                    }
                                    • Set the apiKey property with your API key access token.

                                      MainActivity.kt
                                      22 collapsed lines
                                      package com.example.app
                                      import android.os.Bundle
                                      import androidx.activity.ComponentActivity
                                      import androidx.activity.compose.setContent
                                      import androidx.activity.enableEdgeToEdge
                                      import com.arcgismaps.ApiKey
                                      import com.arcgismaps.ArcGISEnvironment
                                      import com.arcgismaps.httpcore.authentication.OAuthUserConfiguration
                                      import com.arcgismaps.toolkit.authentication.AuthenticatorState
                                      import com.arcgismaps.toolkit.authentication.DialogAuthenticator
                                      import com.example.app.screens.MainScreen
                                      import com.example.app.ui.theme.TutorialTheme
                                      class MainActivity : ComponentActivity() {
                                      private enum class AuthenticationMode { API_KEY, USER_AUTH }
                                      private val authenticationMode = AuthenticationMode.API_KEY
                                      private val authenticatorState = AuthenticatorState()
                                      override fun onCreate(savedInstanceState: Bundle?) {
                                      super.onCreate(savedInstanceState)
                                      when (authenticationMode) {
                                      AuthenticationMode.API_KEY -> {
                                      ArcGISEnvironment.apiKey = ApiKey.create("YOUR_ACCESS_TOKEN")
                                      }
                                      30 collapsed lines
                                      AuthenticationMode.USER_AUTH -> {
                                      authenticatorState.oAuthUserConfigurations = listOf(
                                      OAuthUserConfiguration(
                                      portalUrl = "https://www.arcgis.com",
                                      clientId = "YOUR_CLIENT_ID",
                                      redirectUrl = "YOUR_REDIRECT_URL"
                                      )
                                      )
                                      }
                                      }
                                      enableEdgeToEdge()
                                      setContent {
                                      TutorialTheme {
                                      MainScreen()
                                      if (authenticationMode == AuthenticationMode.USER_AUTH) {
                                      DialogAuthenticator(authenticatorState)
                                      }
                                      }
                                      }
                                      }
                                      }

                                      Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

                                      Run the app

                                      Click Run > Run > app to run the app.

                                      You should see a mapA map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more with the topographic basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more centered on the Santa Monica Mountains in California. Pinch, drag, and double-tap the map view to explore the map.

                                      What’s next?

                                      Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials: