[null,null,["最后更新时间 (UTC):2025-08-16。"],[[["\u003cp\u003eThis guide outlines the setup and configuration process for using the Consumer SDK for Android with Google Cloud Console.\u003c/p\u003e\n"],["\u003cp\u003eSteps include setting up a development project and API key, adding the Consumer SDK and Maps SDK dependencies to your app (explicitly defining the Maps SDK version), and securely adding your API key to your app.\u003c/p\u003e\n"],["\u003cp\u003eFor security, store the API key in the \u003ccode\u003elocal.properties\u003c/code\u003e file instead of the version control system, and reference it within your \u003ccode\u003eAndroidManifest.xml\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eEnsure your app includes required attribution text and open source licenses, typically placed in a legal notices or "About" section, with details found within the "third_party_licenses.txt" file.\u003c/p\u003e\n"],["\u003cp\u003eYour Android app must target a minimum SDK version of 23 or higher to utilize the Consumer SDK.\u003c/p\u003e\n"]]],[],null,["To set up and configure a Google Cloud console to use the Consumer SDK for\nAndroid, follow these steps.\n\n1. [Set up your development project](#auth-project).\n2. [Add the Consumer SDK to your app](#add-sdk).\n3. [Add the API key to your app](#add-key).\n4. [Include the required attributions in your app](#attrib).\n\nFor more details on each step, see the following sections.\n| **Note:** Your app must target `minSdkVersion` 23 or higher.\n\nSet up your development project\n\nIf you don't have a Google Cloud console development project and an API key for\nyour mobility project, you need to set one up. For details, see\n[Create your project](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/create-project) in the Fleet Engine guide.\n\nWhen you're selecting your development project for the Consumer SDK, select the\nsame Google Cloud console project and API key that you are using for Fleet Engine.\n\nAdd the Consumer SDK to your app\n\nThe Consumer SDK is available from the Google Maven repository. The repository\nincludes the SDK's Project Object Model (.pom) files and Javadocs. To add the\nConsumer SDK to your app, add the Consumer SDK and Maps SDK dependencies to your\nGradle or Maven configuration.\n| **Note:** The Consumer SDK depends on the Maps SDK. Set your dependency to an **explicitly defined** version of Maps SDK, as shown in this example. Otherwise, the Consumer SDK uses the minimum-required version of the Maps SDK, which might cause issues if your app relies on features available in later Maps SDK versions.\n\nIn the following examples, substitute `VERSION_NUMBER` with the required\nversion of the Consumer SDK: \n\nGradle\n\nAdd the following to your `build.gradle`: \n\n dependencies {\n ...\n implementation 'com.google.android.libraries.mapsplatform.transportation:transportation-consumer:\u003cvar translate=\"no\"\u003eVERSION_NUMBER\u003c/var\u003e'\n implementation \"com.google.android.gms:play-services-maps:18.1.0\"\n }\n\nMaven\n\nAdd the following to your `pom.xml`: \n\n \u003cdependencies\u003e\n ...\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.android.libraries.mapsplatform.transportation\u003c/groupId\u003e\n \u003cartifactId\u003etransportation-consumer\u003c/artifactId\u003e\n \u003cversion\u003e\u003cvar translate=\"no\"\u003eVERSION_NUMBER\u003c/var\u003e\u003c/version\u003e\n \u003c/dependency\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.android.gms\u003c/groupId\u003e\n \u003cartifactId\u003eplay-services-maps\u003c/artifactId\u003e\n \u003cversion\u003e18.1.0\u003c/version\u003e\n \u003c/dependency\u003e\n \u003c/dependencies\u003e\n\nAdd the API key to your app\n\nOnce you have added the Consumer SDK to your app, add the API key. You must use\nthe project API key you obtained when you set up your development project. For\nmore details, see [Set up your development project](#auth-project) in Step 3 of this guide.\n\nThis section describes how to store your API key so that it can be more securely\nreferenced by your app. For more information on API key security best practices,\nsee the Google Maps Platform article on [API security best practices](/maps/api-security-best-practices#restrict_apikey).\n| **Important:** Don't check your API key into your version control system. Instead, store it in the `local.properties` file, which is located in the root directory of your project. For more information about the `local.properties` file, see [Gradle properties files](https://developer.android.com/studio/build#properties-files).\n\nTo streamline this task, you can use the GitHub documentation [Secrets Gradle\nPlugin for Android](https://github.com/google/secrets-gradle-plugin).\n\nTo install the plugin and store your API key:\n\n1. Open your root-level `build.gradle` file and add the following code to the\n `dependencies` element under `buildscript`.\n\n Groovy \n\n buildscript {\n dependencies {\n // ...\n classpath \"com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0\"\n }\n }\n\n Kotlin \n\n buildscript {\n dependencies {\n // ...\n classpath(\"com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0\")\n }\n }\n\n2. Open your app-level `build.gradle` file and add the following code to the\n `plugins` element.\n\n Groovy \n\n id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'\n\n Kotlin \n\n id(\"com.google.android.libraries.mapsplatform.secrets-gradle-plugin\")\n\n3. If you use Android Studio, sync your project with Gradle. For details, see\n [Sync your project with Gradle](https://developer.android.com/studio/build#sync-files) in the Android documentation.\n\n4. Open the `local.properties` in your project level directory, and then add\n the following code. Replace `YOUR_API_KEY` with your API key.\n\n MAPS_API_KEY=\u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e\n5. In your `AndroidManifest.xml` file, go to `com.google.android.geo.API_KEY`\n and update the `android:value` attribute as follows:\n\n \u003cmeta-data\n android:name=\"com.google.android.geo.API_KEY\"\n android:value=\"${MAPS_API_KEY}\" /\u003e\n\nThe following example shows a complete manifest for a sample app: \n\n \u003cmanifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n package=\"com.example.consumerapidemo\"\u003e\n \u003cuses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" /\u003e\n \u003capplication\n android:allowBackup=\"true\"\n android:icon=\"@mipmap/ic_launcher\"\n android:label=\"@string/app_name\"\n android:supportsRtl=\"true\"\n android:theme=\"@style/_AppTheme\"\u003e\n\n \u003cmeta-data\n android:name=\"com.google.android.geo.API_KEY\"\n android:value=\"${MAPS_API_KEY}\" /\u003e\n\n \u003cactivity android:name=\".MainActivity\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.intent.action.MAIN\" /\u003e\n \u003ccategory android:name=\"android.intent.category.LAUNCHER\" /\u003e\n \u003c/intent-filter\u003e\n \u003c/activity\u003e\n \u003c/application\u003e\n \u003c/manifest\u003e\n\nInclude the required attributions in your app\n\nIf you use the Consumer SDK in your app, you must include attribution text and\nopen source licenses as part of your app's legal notices section. It's best to\ninclude the attributions as an independent menu item or as part of an **About**\nmenu item.\n\nYou can find the license information in the \"third_party_licenses.txt\" file in\nthe unarchived AAR file.\n\nRefer to \u003chttps://developers.google.com/android/guides/opensource\u003e on how to\ninclude open source notices.\n\nWhat's next\n\n[Get authentication tokens](/maps/documentation/mobility/journey-sharing/on-demand/android/auth-sdk)"]]