Google का सुझाव है कि आप अपने Google Ads खाते में एपीआई पासकोड की जांच न करें
वर्शन कंट्रोल सिस्टम पर काम करता है. इसके बजाय, आपको इसे किसी लोकल secrets.properties
फ़ाइल में सेव करना चाहिए,
जो आपके प्रोजेक्ट की रूट डायरेक्ट्री में मौजूद होता है, लेकिन उसे वर्शन कंट्रोल से बाहर रखा जाता है. इसके बाद
Android के लिए सीक्रेट ग्रेडल प्लग इन का इस्तेमाल करें
का इस्तेमाल करें.
Android के लिए सीक्रेट ग्रेडल प्लगिन, एपीआई पासकोड सहित, सीक्रेट टोकन
एक प्रॉपर्टी फ़ाइल जिसे वर्शन कंट्रोल सिस्टम में चेक नहीं किया गया है. इसके बाद प्लगिन उन प्रॉपर्टी को दिखाता है
का इस्तेमाल, Gradle से जनरेट की गई BuildConfig
क्लास और Android मेनिफ़ेस्ट फ़ाइल में वैरिएबल के तौर पर करता है.
एपीआई पासकोड को ऐक्सेस करने के लिए, Android के लिए सीक्रेट ग्रेडल प्लगिन का इस्तेमाल करने के उदाहरण के लिए: Android Studio प्रोजेक्ट सेट अप करना देखें.
इंस्टॉलेशन और इस्तेमाल
अपने Google Maps प्रोजेक्ट में Android के लिए Secrets Gradle प्लग इन इंस्टॉल करने के लिए:
-
Android Studio में, अपना टॉप-लेवल
build.gradle
याbuild.gradle.kts
खोलें फ़ाइल और निम्न कोड कोdependencies
तत्व में जोड़ेंbuildscript
.ग्रूवी
buildscript { dependencies { classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1" } }
Kotlin
buildscript { dependencies { classpath("com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1") } }
-
अपनी मॉड्यूल-लेवल
build.gradle
फ़ाइल खोलें और नीचे दिए गए कोड कोplugins
एलिमेंट.ग्रूवी
plugins { // ... id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' }
Kotlin
plugins { id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") }
- अपनी मॉड्यूल-लेवल
build.gradle
फ़ाइल में, पक्का करें किtargetSdk
औरcompileSdk
को 34 पर सेट किया गया. - फ़ाइल सेव करें और Gredle के साथ प्रोजेक्ट सिंक करते हैं.
-
अपनी शीर्ष-स्तरीय डायरेक्ट्री में
secrets.properties
फ़ाइल खोलें, और फिर जोड़ें .YOUR_API_KEY
को अपनी एपीआई पासकोड से बदलें. अपनी कुंजी इस फ़ाइल में सेव करें ऐसा इसलिए हुआ, क्योंकि वर्शन कंट्रोल मेंsecrets.properties
की जांच नहीं की जा सकी सिस्टम.MAPS_API_KEY=YOUR_API_KEY
- फ़ाइल सेव करें.
-
अपनी टॉप-लेवल डायरेक्ट्री में
local.defaults.properties
फ़ाइल बनाएं. फ़ोल्डर कोsecrets.properties
फ़ाइल के रूप में चुनकर यह कोड जोड़ें.MAPS_API_KEY=DEFAULT_API_KEY
इस फ़ाइल का मकसद, एपीआई पासकोड के लिए बैकअप जगह की जानकारी देना है, अगर
secrets.properties
फ़ाइल नहीं मिली है, ताकि बिल्ड विफल न हो. ऐसा तब हो सकता है, जब आपने वर्शन कंट्रोल सिस्टम से ऐप्लिकेशन का क्लोन बनाया है. इसमेंsecrets.properties
और आपने अभी तक स्थानीय भाषा मेंsecrets.properties
फ़ाइल नहीं बनाई है. एपीआई पासकोड. - फ़ाइल सेव करें.
-
अपनी
AndroidManifest.xml
फ़ाइल में, इस पर जाएंcom.google.android.geo.API_KEY
औरandroid:value attribute
अपडेट करें. अगर<meta-data>
टैग मौजूद नहीं है, तो उसे<application>
टैग.<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 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
orbuild.gradle.kts
file and edit thesecrets
property. If thesecrets
property does not exist, add it.Edit the properties of the plugin to set
propertiesFileName
tosecrets.properties
, setdefaultPropertiesFileName
tolocal.defaults.properties
, and set any other 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" // Configure which keys should be ignored by the plugin by providing regular expressions. // "sdk.dir" is ignored by default. ignoreList.add("keyToIgnore") // Ignore the key "keyToIgnore" ignoreList.add("sdk.*") // Ignore all keys matching the regexp "sdk.*" }
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" // Configure which keys should be ignored by the plugin by providing regular expressions. // "sdk.dir" is ignored by default. ignoreList.add("keyToIgnore") // Ignore the key "keyToIgnore" ignoreList.add("sdk.*") // Ignore all keys matching the regexp "sdk.*" }
आगे क्या करना है
- Android के लिए सीक्रेट ग्रेडल प्लग इन देखें GitHub प्रोजेक्ट पेज.
- उदाहरण के लिए, Android Studio प्रोजेक्ट सेट अप करना लेख पढ़ें. प्लगिन.
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2024-08-17 (UTC) को अपडेट किया गया.
[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"वह जानकारी मौजूद नहीं है जो मुझे चाहिए" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"बहुत मुश्किल है / बहुत सारे चरण हैं" },{ "type": "thumb-down", "id": "outOfDate", "label":"पुराना" },{ "type": "thumb-down", "id": "translationIssue", "label":"अनुवाद से जुड़ी समस्या" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"सैंपल / कोड से जुड़ी समस्या" },{ "type": "thumb-down", "id": "otherDown", "label":"अन्य" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"समझने में आसान है" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"मेरी समस्या हल हो गई" },{ "type": "thumb-up", "id": "otherUp", "label":"अन्य" }]