Stay organized with collections Save and categorize content based on your preferences.
This page describes how to configure an Android Studio project to use the Maps SDK for Android without using the Google Maps template that is detailed in the Quickstart.
The Google Maps template automatically configures and adds a basic map to a new Android Studio project. However, you can also add a map to an Android project that uses a different Android Studio template. To do so, you need to manually configure your project and then add the map.
Step 1: Set up Android StudioThis document describes a development environment using Android Studio Hedgehog and the Android Gradle plugin version 8.2.
Note: If your development environment uses a different version of Android Studio or Gradle you might have to modify the steps based on those versions. For more information about Android Studio and Gradle versions, see Android Gradle plugin and Android Studio compatibility. Step 2. Set up the SDKThe Maps SDK for Android library is available through Google's Maven repository. To add the SDK to your app, do the following:
settings.gradle.kts
file, include the Gradle plugin portal, Google Maven repository, and Maven central repository under the pluginManagement
block. The pluginManagement
block must appear before any other statements in the script.
pluginManagement { repositories { gradlePluginPortal() google() mavenCentral() } }
settings.gradle.kts
file, include the Google's Maven repository and Maven central repository under the dependencyResolutionManagement
block:
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } }
build.gradle.kts
or build.gradle
file, add the Google Play services dependency for the Maps SDK for Android. Kotlin
dependencies { // Maps SDK for Android implementation("com.google.android.gms:play-services-maps:19.2.0") }Groovy
dependencies { // Maps SDK for Android implementation "com.google.android.gms:play-services-maps:19.0.0" }
build.gradle.kts
or build.gradle
file, set compileSdk
and minSdk
to the following values: Note: Ensure that compileSdk
is set to 34 or higher and minSdk
is set to 21 or higher. Kotlin
android { compileSdk = 34 defaultConfig { minSdk = 21 // ... } }Groovy
android { compileSdk 34 defaultConfig { minSdk 21 // ... } }
buildFeatures
section of your module-level build.gradle.kts
or build.gradle
file, add the BuildConfig
class, which you can use to access metadata values defined later in this procedure: Kotlin
android { // ... buildFeatures { buildConfig = true // ... } }Groovy
android { // ... buildFeatures { buildConfig true // ... } }
This section describes how to store your API key so that it can be securely referenced by your app. You should not check your API key into your version control system, so we recommend storing it in the secrets.properties
file, which is located in the root directory of your project. For more information about the secrets.properties
file, see Gradle properties files.
To streamline this task, we recommend that you use the Secrets Gradle Plugin for Android.
Note: See the Secrets 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:
build.gradle.kts
or build.gradle
file and add the following code to the dependencies
element under buildscript
. Kotlin
buildscript { dependencies { classpath("com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1") } }Groovy
buildscript { dependencies { classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1" } }
build.gradle.kts
or build.gradle
file and add the following code to the plugins
element. Kotlin
plugins { // ... id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") }Groovy
plugins { // ... id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' }
build.gradle.kts
or build.gradle
file, ensure that targetSdk
and compileSdk
are set to 34.secrets.properties
file in your top-level directory, and then add the following code. Replace YOUR_API_KEY
with your API key. Store your key in this file because secrets.properties
is excluded from being checked into a version control system. Note: If the secrets.properties
file does not exist, create it in the same folder as the local.properties
file.
MAPS_API_KEY=YOUR_API_KEY
Create the local.defaults.properties
file in your top-level directory, the same folder as the secrets.properties
file, and then add the following code.
DEFAULT_API_KEY
with 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.properties
file is not found so that builds don't fail. This can happen if you clone the app from a version control system which omits secrets.properties
and you have not yet created a secrets.properties
file locally to provide your API key.
AndroidManifest.xml
file, go to com.google.android.geo.API_KEY
and update the android:value attribute
. If the <meta-data>
tag does not exist, create it as a child of the <application>
tag.
<meta-data android:name="com.google.android.geo.API_KEY" android:value="${MAPS_API_KEY}" />
Note: com.google.android.geo.API_KEY
is 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 name com.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.kts
or build.gradle
file and edit the secrets
property. If the secrets
property does not exist, add it.
Edit the properties of the plugin to set propertiesFileName
to secrets.properties
, set defaultPropertiesFileName
to local.defaults.properties
, and set any other properties.
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_KEY propertiesFileName = "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_KEY propertiesFileName = "secrets.properties" // A properties file containing default secret values. This file can be // checked in version control. defaultPropertiesFileName = "local.defaults.properties" }
This section describes the settings to add to your AndroidManifest.xml
file.
Add the following declaration within the application
element. This embeds the version of Google Play services that the app was compiled with.
<meta-data
android: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 the location permission in your AndroidManifest.xml
file. The options are ACCESS_FINE_LOCATION
, which provides the precise device location, and ACCESS_COARSE_LOCATION
, which is less precise. For details, see the location data guide.
ACCESS_FINE_LOCATION
enabled.
To request the ACCESS_FINE_LOCATION
permission, add this code to the manifest
element:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
External storage permission
If you're targeting version 8.3 or later of the Google Play services SDK, you don't need the WRITE_EXTERNAL_STORAGE
permission. If you're targeting earlier versions of the Google Play services SDK, you must request the WRITE_EXTERNAL_STORAGE permission, in the manifest
element.
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Apache HTTP Legacy library
If you are using com.google.android.gms:play-services-maps:16.0.0
or below and your app is targeting API level 28 (Android 9.0) or above, you must include the following declaration within the <application>
element of AndroidManifest.xml
. Otherwise, skip this declaration.
<uses-library
android: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.
Maps SDK for Android requires that the device on which you deploy your app has the Google Play services installed. Google provides a method that you can call from your app to check. For more information, see Check whether Google Play services is installed.
Next stepsOnce your project is configured, you can add a map.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["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."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4