Set up an Android Studio project Stay organized with collections Save and categorize content based on your preferences.
AI-generated Key Takeaways
This guide explains how to manually configure an Android Studio project to use the Maps SDK for Android without the default Google Maps template.
You will need to set up the Android SDK, add your API key securely, and update the app manifest with necessary permissions and settings.
Ensure your Android device or emulator has Google Play services installed and is based on Android 5.0 or higher with the Google APIs.
Optionally, you can implement a check within your app to ensure Google Play services are available on the user's device.
This page describes how to configure an Android Studio project to use theMaps SDK for Android without using the Google Maps templatethat is detailed in theQuickstart.
The Google Maps template automatically configures and adds a basic map to a newAndroid Studio project. However, you can also add a map to an Android projectthat uses a different Android Studio template. To do so, you need to manuallyconfigure your project and thenadd the map.
Step 1: Set up Android Studio
This document describes a development environment usingAndroid Studio Hedgehog and theAndroid Gradle pluginversion 8.2.
Note:If your development environment uses a different versionof Android Studio or Gradle you might have to modify the steps based on those versions. For moreinformation about Android Studio and Gradle versions, seeAndroid Gradle plugin and Android Studio compatibility.Step 2. Set up the SDK
The Maps SDK for Android library is available throughGoogle's Maven repository. Toadd the SDK to your app, do the following:
- In your top-level
settings.gradle.ktsfile, include theGradle plugin portal,Google Maven repository, andMaven central repository under thepluginManagementblock. ThepluginManagementblock must appear before any other statements in the script.pluginManagement {repositories {gradlePluginPortal()google()mavenCentral()}}
- In your top-level
settings.gradle.ktsfile, include theGoogle's Maven repository andMaven central repository under thedependencyResolutionManagementblock:dependencyResolutionManagement {repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories {google()mavenCentral()}}
- In your module-level
build.gradle.ktsorbuild.gradlefile, add theGoogle Play services dependency for the Maps SDK for Android.Kotlin
dependencies{// Maps SDK for Androidimplementation(libs.play.services.maps)}
Groovy
dependencies{// Maps SDK for Androidimplementation"com.google.android.gms:play-services-maps:19.0.0"}
- In your module-level
build.gradle.ktsorbuild.gradlefile, setcompileSdkandminSdkto the following values:Note: Ensure thatcompileSdkis set to 34 or higher andminSdkis set to 21 or higher.Kotlin
android{compileSdk=34defaultConfig{minSdk=21// ...}}
Groovy
android{compileSdk34defaultConfig{minSdk21// ...}}
- In the
buildFeaturessection of your module-levelbuild.gradle.ktsorbuild.gradlefile, add theBuildConfigclass, which you can use to access metadata values defined later in this procedure:Kotlin
android{// ...buildFeatures{buildConfig=true// ...}}
Groovy
android{// ...buildFeatures{buildConfigtrue// ...}}
Step 3: Add your API key to the project
This section describes how to store your API key so that it can be securely referenced byyour app. You should not check your API key into your version control system, so we recommendstoring it in thesecrets.properties file, which is located in the root directory of yourproject. For more information about thesecrets.properties file, seeGradle properties files.
To streamline this task, we recommend that you use theSecrets Gradle Plugin for Android.
Note:See theSecrets Gradle Plugin for Android documentation on GitHub for the latest system requirements and installation instructions.To install the Secrets Gradle Plugin for Android in your Google Maps project:
- In Android Studio, open your top-level
build.gradle.ktsorbuild.gradlefile and add the following code to thedependencieselement underbuildscript.Kotlin
plugins {alias(libs.plugins.android.application) apply falsealias(libs.plugins.jetbrains.kotlin.android) apply falsealias(libs.plugins.kotlin.compose) apply falsealias(libs.plugins.secrets.gradle.plugin) apply false}
Groovy
buildscript {dependencies {classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1"}}
- Open your module-level
build.gradle.ktsorbuild.gradlefile and add the following code to thepluginselement.Kotlin
plugins{// ...alias(libs.plugins.secrets.gradle.plugin)}
Groovy
plugins {// ...id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'}
- In your module-level
build.gradle.ktsorbuild.gradlefile, ensure thattargetSdkandcompileSdkare set to 34. - Sync your project with Gradle.
- Open the
secrets.propertiesfile in your top-level directory, and then add the following code. ReplaceYOUR_API_KEYwith your API key. Store your key in this file becausesecrets.propertiesis excluded from being checked into a version control system.Note:If thesecrets.propertiesfile does not exist, create it in the same folder as thelocal.propertiesfile.MAPS_API_KEY=YOUR_API_KEY
Create the
Note:Enter the code as shown. Don't replacelocal.defaults.propertiesfile in your top-level directory, the same folder as thesecrets.propertiesfile, and then add the following code.DEFAULT_API_KEYwith your API key.MAPS_API_KEY=DEFAULT_API_KEY
The purpose of this file is to provide a backup location for the API key if the
secrets.propertiesfile is not found so that builds don't fail. This can happen if you clone the app from a version control system which omitssecrets.propertiesand you have not yet created asecrets.propertiesfile locally to provide your API key.- In your
AndroidManifest.xmlfile, go tocom.google.android.geo.API_KEYand update theandroid:value attribute. If the<meta-data>tag does not exist, create it as a child of the<application>tag.<meta-dataandroid:name="com.google.android.geo.API_KEY"android:value="${MAPS_API_KEY}"/>
Note:
com.google.android.geo.API_KEYis the recommended metadata name for the API key. A key with this name can be used to authenticate to multiple Google Maps-based APIs on the Android platform, including the Maps SDK for Android. For backwards compatibility, the API also supports the namecom.google.android.maps.v2.API_KEY. This legacy name allows authentication to the Android Maps API v2 only. An application can specify only one of the API key metadata names. If both are specified, the API throws an exception. In Android Studio, open your module-level
build.gradle.ktsorbuild.gradlefile and edit thesecretsproperty. If thesecretsproperty does not exist, add it.Edit the properties of the plugin to set
propertiesFileNametosecrets.properties, setdefaultPropertiesFileNametolocal.defaults.properties, and set any other properties.Kotlin
secrets{// To add your Maps API key to this project:// 1. If the secrets.properties file does not exist, create it in the same folder as the local.properties file.// 2. Add this line, where YOUR_API_KEY is your API key:// MAPS_API_KEY=YOUR_API_KEYpropertiesFileName="secrets.properties"// A properties file containing default secret values. This file can be// checked in version control.defaultPropertiesFileName="local.defaults.properties"}
Groovy
secrets{// To add your Maps API key to this project:// 1. If the secrets.properties file does not exist, create it in the same folder as the local.properties file.// 2. Add this line, where YOUR_API_KEY is your API key:// MAPS_API_KEY=YOUR_API_KEYpropertiesFileName="secrets.properties"// A properties file containing default secret values. This file can be// checked in version control.defaultPropertiesFileName="local.defaults.properties"}
Step 4: Update the app manifest
This section describes the settings to add to yourAndroidManifest.xml file.
Google Play services version number
Add the following declaration within theapplication element. This embedsthe version of Google Play services that the app was compiled with.
<meta-dataandroid:name="com.google.android.gms.version"android:value="@integer/google_play_services_version"/>Location permission
If your app needs to access the user's location, you need to request thelocation permission in yourAndroidManifest.xml file. The options areACCESS_FINE_LOCATION, which provides the precise device location, andACCESS_COARSE_LOCATION, which is less precise. For details, see thelocation data guide.
ACCESS_FINE_LOCATION enabled.To request theACCESS_FINE_LOCATION permission, add this code to themanifest element:
<uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/>External storage permission
If you're targetingversion 8.3 or later of the Google Play services SDK,you don't need theWRITE_EXTERNAL_STORAGE permission. If you're targetingearlier versions of the Google Play services SDK, you must request theWRITE_EXTERNAL_STORAGEpermission, in themanifest element.
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>Apache HTTP Legacy library
If you are usingcom.google.android.gms:play-services-maps:16.0.0 or below andyour app is targeting API level 28 (Android 9.0) or above, you must includethe following declaration within the<application> element ofAndroidManifest.xml. Otherwise, skip this declaration.
<uses-libraryandroid:name="org.apache.http.legacy"android:required="false"/>Step 5: Set up an Android device
To run an app that uses the Maps SDK for Android, you must deploy it to an Android device or Android emulator that is based on Android 5.0 or higher and includes the Google APIs.
- To use an Android device, follow the instructions atRun apps on a hardware device.
- To use an Android emulator, you can create a virtual device and install the emulator by using theAndroid Virtual Device (AVD) Manager that comes with Android Studio.Note:If you choose to use an Android emulator, ensure that you choose a device with thePlay icon,
, displayed under thePlay Store column. This icon indicates that these profiles are fullyCTS compliant and may use system images that include the Play Store app:
Step 6: Optionally check for Play Service support
Maps SDK for Android requires that the device on which you deploy yourapp has the Google Play services installed. Google provides a method that youcan call from your app to check. For more information, seeCheck whether GooglePlay services is installed.
Next steps
Once your project is configured, you canadd a map.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-11-21 UTC.