सीक्रेट ग्रेडल प्लग इन

Google का सुझाव है कि आप अपने Google Ads खाते में एपीआई पासकोड की जांच न करें वर्शन कंट्रोल सिस्टम पर काम करता है. इसके बजाय, आपको इसे किसी लोकल secrets.properties फ़ाइल में सेव करना चाहिए, जो आपके प्रोजेक्ट की रूट डायरेक्ट्री में मौजूद होता है, लेकिन उसे वर्शन कंट्रोल से बाहर रखा जाता है. इसके बाद Android के लिए सीक्रेट ग्रेडल प्लग इन का इस्तेमाल करें का इस्तेमाल करें.

Android के लिए सीक्रेट ग्रेडल प्लगिन, एपीआई पासकोड सहित, सीक्रेट टोकन एक प्रॉपर्टी फ़ाइल जिसे वर्शन कंट्रोल सिस्टम में चेक नहीं किया गया है. इसके बाद प्लगिन उन प्रॉपर्टी को दिखाता है का इस्तेमाल, Gradle से जनरेट की गई BuildConfig क्लास और Android मेनिफ़ेस्ट फ़ाइल में वैरिएबल के तौर पर करता है.

एपीआई पासकोड को ऐक्सेस करने के लिए, Android के लिए सीक्रेट ग्रेडल प्लगिन का इस्तेमाल करने के उदाहरण के लिए: Android Studio प्रोजेक्ट सेट अप करना देखें.

इंस्टॉलेशन और इस्तेमाल

अपने Google Maps प्रोजेक्ट में Android के लिए Secrets Gradle प्लग इन इंस्टॉल करने के लिए:

  1. 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")
        }
    }
    
  2. अपनी मॉड्यूल-लेवल build.gradle फ़ाइल खोलें और नीचे दिए गए कोड को plugins एलिमेंट.

    ग्रूवी

    plugins {
        // ...
        id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
    }

    Kotlin

    plugins {
        id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
    }
  3. अपनी मॉड्यूल-लेवल build.gradle फ़ाइल में, पक्का करें कि targetSdk और compileSdk को 34 पर सेट किया गया.
  4. फ़ाइल सेव करें और Gredle के साथ प्रोजेक्ट सिंक करते हैं.
  5. अपनी शीर्ष-स्तरीय डायरेक्ट्री में secrets.properties फ़ाइल खोलें, और फिर जोड़ें . YOUR_API_KEY को अपनी एपीआई पासकोड से बदलें. अपनी कुंजी इस फ़ाइल में सेव करें ऐसा इसलिए हुआ, क्योंकि वर्शन कंट्रोल में secrets.properties की जांच नहीं की जा सकी सिस्टम.
    MAPS_API_KEY=YOUR_API_KEY
  6. फ़ाइल सेव करें.
  7. अपनी टॉप-लेवल डायरेक्ट्री में local.defaults.properties फ़ाइल बनाएं. फ़ोल्डर को secrets.properties फ़ाइल के रूप में चुनकर यह कोड जोड़ें.

    MAPS_API_KEY=DEFAULT_API_KEY

    इस फ़ाइल का मकसद, एपीआई पासकोड के लिए बैकअप जगह की जानकारी देना है, अगर secrets.properties फ़ाइल नहीं मिली है, ताकि बिल्ड विफल न हो. ऐसा तब हो सकता है, जब आपने वर्शन कंट्रोल सिस्टम से ऐप्लिकेशन का क्लोन बनाया है. इसमें secrets.properties और आपने अभी तक स्थानीय भाषा में secrets.properties फ़ाइल नहीं बनाई है. एपीआई पासकोड.

  8. फ़ाइल सेव करें.
  9. अपनी 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 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.

  10. In Android Studio, open your module-level build.gradle or build.gradle.kts 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.

    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.*"
    }
            

आगे क्या करना है