A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/maps/documentation/places/android-sdk/config below:

Set up an Android Studio project | Places SDK for Android

Skip to main content Set up an Android Studio project

Stay organized with collections Save and categorize content based on your preferences.

NOTICE: Version 2.0.0 and later of the Places SDK for Android is dependent on AndroidX. Beginning with this version, the old support library will no longer be supported. In order to retain compatibility, you must migrate your projects to use AndroidX.

To configure your app to use the Places SDK for Android, follow these steps. They are required for all apps using the Places SDK for Android.

Step 1: Set up Android Studio

This 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 SDK

The Places SDK for Android library is available through Google's Maven repository. To add the SDK to your app, do the following:

  1. In your top-level 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()
        }
    } 
  2. In your top-level 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()
        }
    } 
  3. In the dependencies section of your module-level build.gradle.kts file, add a dependency to the Places SDK for Android:

    Note: Places SDK for Android version 3.5.0 requires kotlin-bom 1.8.0 or later. For more information on the kotlin-bom dependency, see Usage of the latest kotlin-stdlib version in transitive dependencies. Groovy
    dependencies {
        implementation(platform("org.jetbrains.kotlin:kotlin-bom:$kotlin_version"))
        implementation("com.google.android.libraries.places:places:3.5.0")
    }
    Kotlin
              dependencies {
    
        // Places and Maps SDKs
        implementation("com.google.android.libraries.places:places:4.3.1")
    }
  4. In your module-level build.gradle.kts file, set compileSdk and minSdk to the following values: Note: Ensure that compileSdk is set to 34 or higher and minSdk is set to 23 or higher. Groovy
    android {
        compileSdk 34
    
        defaultConfig {
            minSdk 23
            // ...
        }
    }
    Kotlin
    android {
        compileSdk = 34
    
        defaultConfig {
            minSdk = 23
            // ...
        }
    }
  5. In the buildFeatures section of your module-level build.gradle file, add the BuildConfig class, which you use to access metadata values defined later in this procedure: Groovy
    android {
      // ...
      buildFeatures {
        buildConfig true
        // ...
      }
    }
    Kotlin
    android {
      // ...
      buildFeatures {
        buildConfig = true
        // ...
      }
    }
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 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:

  1. In Android Studio, open your top-level 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"
        }
    }
  2. Open your module-level 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'
    }
  3. In your module-level build.gradle.kts or build.gradle file, ensure that targetSdk and compileSdk are set to 34.
  4. Sync your project with Gradle.
  5. Open the 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.
    PLACES_API_KEY=YOUR_API_KEY
  6. 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.

    Note: Enter the code as shown. Don't replace DEFAULT_API_KEY with your API key.
    PLACES_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.

  7. 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.

    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_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"
    }
            
Step 4. Initialize the Places API client

Initialize the Places SDK for Android within an activity or fragment. You must first decide which version of the SDK to use: Places SDK for Android or Places SDK for Android (New). For more information on product versions, see Choose your SDK version.

The following example shows how to initialize the SDK for both versions.

Places SDK for Android (New)

Pass the API key when calling Places.initializeWithNewPlacesApiEnabled():

Kotlin
    // Define a variable to hold the Places API key.
    val apiKey = BuildConfig.PLACES_API_KEY

    // Log an error if apiKey is not set.
    if (apiKey.isEmpty() || apiKey == "DEFAULT_API_KEY") {
        Log.e("Places test", "No api key")
        finish()
        return
    }

    // Initialize the SDK
    Places.initializeWithNewPlacesApiEnabled(applicationContext, apiKey)

    // Create a new PlacesClient instance
    val placesClient = Places.createClient(this)
    
Java
    // Define a variable to hold the Places API key.
    String apiKey = BuildConfig.PLACES_API_KEY;

    // Log an error if apiKey is not set.
    if (TextUtils.isEmpty(apiKey) || apiKey.equals("DEFAULT_API_KEY")) {
      Log.e("Places test", "No api key");
      finish();
      return;
    }

    // Initialize the SDK
    Places.initializeWithNewPlacesApiEnabled(getApplicationContext(), apiKey);

    // Create a new PlacesClient instance
    PlacesClient placesClient = Places.createClient(this);
    
Places SDK for Android

Pass the API key when calling Places.initialize():

Kotlin
    // Define a variable to hold the Places API key.
    val apiKey = BuildConfig.PLACES_API_KEY

    // Log an error if apiKey is not set.
    if (apiKey.isEmpty() || apiKey == "DEFAULT_API_KEY") {
        Log.e("Places test", "No api key")
        finish()
        return
    }

    // Initialize the SDK
    Places.initialize(applicationContext, apiKey)

    // Create a new PlacesClient instance
    val placesClient = Places.createClient(this)
    
Java
    // Define a variable to hold the Places API key.
    String apiKey = BuildConfig.PLACES_API_KEY;

    // Log an error if apiKey is not set.
    if (TextUtils.isEmpty(apiKey) || apiKey.equals("DEFAULT_API_KEY")) {
      Log.e("Places test", "No api key");
      finish();
      return;
    }

    // Initialize the SDK
    Places.initialize(getApplicationContext(), apiKey);

    // Create a new PlacesClient instance
    PlacesClient placesClient = Places.createClient(this);
    
IMPORTANT: Never add API keys directly to application code. In production environments, we recommend using a secure mechanism to manage API keys.

You are now ready to begin using the Places SDK for Android!

Step 5: Set up an Android device

To run an app that uses the Places 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.

Next steps

After your project is configured, you can explore the

sample apps

.

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."],[[["The Places SDK for Android now requires AndroidX and uses the Android Gradle plugin version 8.2, with compatibility information available for other versions."],["You need to configure your project with the Places SDK dependency, an API key stored securely via the Secrets Gradle Plugin, and initialize the Places API client."],["Ensure your development environment is set up with Android Studio Hedgehog and deploy your application to a compatible Android device or emulator running Android 5.0 or higher with Google APIs."],["Securely manage API keys in production using recommended mechanisms, and refer to provided sample apps for practical implementation guidance."]]],[]]


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