अपना प्रोजेक्ट सेट करें -- 4.99 और इससे पहले के वर्शन

इस गाइड में, बिल्ड कॉन्फ़िगरेशन की ज़रूरी शर्तों के बारे में बताया गया है. Android के लिए नेविगेशन SDK टूल. निर्देशों में यह माना जाता है कि आपके पास एक Android IDE है इंस्टॉल किए हुए हैं और Android डेवलपमेंट के बारे में जानते हैं.

नेविगेशन SDK टूल का इस्तेमाल करने के लिए ज़रूरी शर्तें

ये ज़रूरी शर्तें, Android 4.99 और इससे पहले के वर्शन वाले नेविगेशन SDK टूल पर लागू होती हैं.

  • Google Cloud Console प्रोजेक्ट, जिसमें नेविगेशन SDK टूल चालू हो. प्रावधान करने के लिए, अपने Google Maps Platform प्रतिनिधि से संपर्क करें.

  • आपके ऐप्लिकेशन को, एपीआई लेवल 30 या उसके बाद के लेवल को टारगेट करना होगा.

  • नेविगेशन SDK टूल की मदद से बनाए गए किसी ऐप्लिकेशन को चलाने के लिए, Android डिवाइस में Google Play services होना ज़रूरी है इंस्टॉल और चालू किया जा सकता है.

  • एट्रिब्यूशन और लाइसेंस से जुड़ा टेक्स्ट ऐप्लिकेशन में जोड़ा जाना चाहिए.

अपने प्रोजेक्ट सेट अप करें: Cloud Console प्रोजेक्ट और Android प्रोजेक्ट

किसी ऐप्लिकेशन को बनाने या उसकी जांच करने से पहले, आपको एक Cloud Console प्रोजेक्ट बनाना होगा और एपीआई कुंजी के क्रेडेंशियल जोड़ें. प्रोजेक्ट में नेविगेशन SDK टूल. Cloud Console प्रोजेक्ट में मौजूद सभी कुंजियां उन्हें नेविगेशन SDK टूल का वही ऐक्सेस दिया जाता है. एक कुंजी एक से ज़्यादा डेवलपमेंट प्रोजेक्ट हो सकते हैं. अगर आपके पास पहले से कोई कंसोल प्रोजेक्ट है, तो अपने मौजूदा प्रोजेक्ट में कुंजी जोड़ी जा सकती है.

सेट अप करने के लिए

  1. अपने पसंदीदा वेब ब्राउज़र में, साइन इन करें Cloud Console पर जाकर अपना Cloud Console प्रोजेक्ट.
  2. अपने IDE, जैसे कि Android Studio में, Android ऐप्लिकेशन डेवलपमेंट बनाएं प्रोजेक्ट खोलें और पैकेज का नाम नोट करें.
  3. ऐक्सेस देने के लिए, Google Maps Platform प्रतिनिधि से संपर्क करें Cloud Console के लिए नेविगेशन SDK टूल प्रोजेक्ट.
  4. अपने वेब ब्राउज़र में Cloud Console के डैशबोर्ड पर जाकर, कुछ पाबंदियों के साथ एपीआई पासकोड जनरेट करने के लिए, क्रेडेंशियल बनाएं.
  5. एपीआई पासकोड पेज पर जाकर, ऐप्लिकेशन से जुड़ी पाबंदियां में जाकर Android ऐप्लिकेशन पर क्लिक करें क्षेत्र.
  6. पैकेज का नाम और फ़िंगरप्रिंट जोड़ें पर क्लिक करें. इसके बाद, पैकेज डालें आपके डेवलपमेंट प्रोजेक्ट का नाम और उस कुंजी के लिए SHA-1 फ़िंगरप्रिंट होगा.
  7. सेव करें पर क्लिक करें.

अपने प्रोजेक्ट में नेविगेशन SDK टूल जोड़ना

नेविगेशन SDK टूल, Maven के ज़रिए या एएआर बंडल. अपना डेवलपमेंट प्रोजेक्ट बनाने के बाद, SDK टूल को इसमें इंटिग्रेट किया जा सकता है. इसके लिए: इनमें से किसी एक तरीके का इस्तेमाल करके.

यहां google() मेवन रिपॉज़िटरी का इस्तेमाल किया गया है, जो कि सबसे आसान है और नेविगेशन SDK टूल को अपने प्रोजेक्ट

  1. अपने Gradle या Maven कॉन्फ़िगरेशन में ये डिपेंडेंसी जोड़ें, VERSION_NUMBER प्लेसहोल्डर को Android के लिए नेविगेशन SDK का मनचाहा वर्शन पाएं.

    ग्रेडल

    अपने मॉड्यूल-लेवल build.gradle में यह जोड़ें:

    dependencies {
      ...
      implementation 'com.google.android.libraries.navigation:navigation:VERSION_NUMBER'
    }
    

    अगर ओरिजनल Maven रिपॉज़िटरी से अपग्रेड किया जा रहा है, तो ध्यान रखें कि ग्रुप और आर्टफ़ैक्ट के नाम बदल गए हैं और com.google.cloud.artifactregistry.gradle-plugin प्लगिन अब नहीं है ज़रूरी है.

    साथ ही, अपने टॉप-लेवल build.gradle में इन्हें जोड़ें:

    allprojects {
       ...
       // Required: you must exclude the Google Play service Maps SDK from
       // your transitive dependencies. This is to ensure there won't be
       // multiple copies of Google Maps SDK in your binary, as the Navigation
       // SDK already bundles the Google Maps SDK.
       configurations {
           implementation {
               exclude group: 'com.google.android.gms', module: 'play-services-maps'
           }
       }
    }
    

    Maven

    अपने pom.xml में यह जोड़ें:

    <dependencies>
      ...
      <dependency>
        <groupId>com.google.android.libraries.navigation</groupId>
        <artifactId>navigation</artifactId>
        <version>VERSION_NUMBER</version>
      </dependency>
    </dependencies>
    

    अगर आपके पास Maps SDK का इस्तेमाल करने वाली कोई डिपेंडेंसी है, तो आपको में बताई गई हर डिपेंडेंसी, Maps SDK पर निर्भर करती है.

    <dependencies>
      <dependency>
      <groupId>project.that.brings.in.maps</groupId>
      <artifactId>MapsConsumer</artifactId>
      <version>1.0</version>
        <exclusions>
          <!-- Navigation SDK already bundles Maps SDK. You must exclude it to prevent duplication-->
          <exclusion>  <!-- declare the exclusion here -->
            <groupId>com.google.android.gms</groupId>
            <artifactId>play-services-maps</artifactId>
          </exclusion>
        </exclusions>
      </dependency>
    </dependencies>
    

v4.5 से पहले के वर्शन या ड्राइवर SDK के साथ नेविगेशन SDK के लिए Maven का इस्तेमाल करना

नेविगेशन SDK टूल, v4 वर्शन के बाकी बचे हुए वर्शन के ज़रिए मूल Maven रिपॉज़िटरी की जानकारी दी गई है. यह है ऊपर दिए गए वर्शन के समान अपडेट वाली लाइब्रेरी है, और इसमें ट्रांज़िशन के दौरान, ड्राइवर SDK टूल और अन्य लाइब्रेरी के साथ काम करता है. इसका इस्तेमाल किया जा रहा है इस डिपेंडेंसी के लिए gcloud से अपने क्लाउड प्रोजेक्ट में लॉग इन करना ज़रूरी है. ऐसा तब होता है, जब कंपाइल करना.

  1. Google की Maven रिपॉज़िटरी को ऐक्सेस करने के लिए, अपना एनवायरमेंट सेट अप करें. इसकी जानकारी यहां दी गई है ज़रूरी शर्तें सेक्शन में देखें. नेविगेशन SDK टूल को Workspace ग्रुप से कंट्रोल किया जाता है.
  2. अपने Gradle या Maven कॉन्फ़िगरेशन में ये डिपेंडेंसी जोड़ें नेविगेशन SDK टूल के मनमुताबिक वर्शन के लिए VERSION_NUMBER प्लेसहोल्डर.

    ग्रेडल

    अपने मॉड्यूल-लेवल build.gradle में यह जोड़ें:

    dependencies {
      ...
      implementation 'com.google.android.maps:navsdk:VERSION_NUMBER'
    }
    

    साथ ही, अपने टॉप-लेवल build.gradle में इन्हें जोड़ें:

    allprojects {
       ...
       // Required: you must exclude the Google Play service Maps SDK from
       // your transitive dependencies. This is to ensure there won't be
       // multiple copies of Google Maps SDK in your binary, as the Navigation
       // SDK already bundles the Google Maps SDK.
       configurations {
           implementation {
               exclude group: 'com.google.android.gms', module: 'play-services-maps'
           }
       }
    }
    

    Maven

    अपने pom.xml में यह जोड़ें:

    <dependencies>
      ...
      <dependency>
        <groupId>com.google.android.maps</groupId>
        <artifactId>navsdk</artifactId>
        <version>VERSION_NUMBER</version>
      </dependency>
    </dependencies>
    

    अगर आपके पास Maps SDK का इस्तेमाल करने वाली कोई डिपेंडेंसी है, तो आपको में बताई गई हर डिपेंडेंसी, Maps SDK पर निर्भर करती है.

    <dependencies>
      <dependency>
      <groupId>project.that.brings.in.maps</groupId>
      <artifactId>MapsConsumer</artifactId>
      <version>1.0</version>
        <exclusions>
          <!-- Navigation SDK already bundles Maps SDK. You must exclude it to prevent duplication-->
          <exclusion>  <!-- declare the exclusion here -->
            <groupId>com.google.android.gms</groupId>
            <artifactId>play-services-maps</artifactId>
          </exclusion>
        </exclusions>
      </dependency>
    </dependencies>
    

नेविगेशन SDK टूल, एएआर बंडल के तौर पर भी उपलब्ध है. डेवलपमेंट प्रोजेक्ट बनाने के बाद, SDK टूल को इंटिग्रेट किया जा सकता है. ये निर्देश मान लें कि आपके IDE के लिए Android Studio का इस्तेमाल किया जा सकता है.

  1. नेविगेशन SDK टूल का सबसे नया वर्शन डाउनलोड करें शेयर की गई Google डिस्क से हटाएं और उसे अनज़िप करें. अगर आपको ऐक्सेस नहीं है, तो अपने प्रतिनिधि से संपर्क करें.

  2. Android Studio में, कोई प्रोजेक्ट खोलें और Google Play services पैकेज जोड़ें SDK Manager के ज़रिए ऐक्सेस किया जा सकता है.

  3. ZIP फ़ाइल डायरेक्ट्री से, libs/google_navigation_navmap.aar को इसमें कॉपी करें आपके प्रोजेक्ट की app/libs डायरेक्ट्री.

  4. अपने मॉड्यूल-लेवल build.gradle में यह जोड़ें:

    implementation(name: 'google_navigation_navmap', ext: 'aar')
    

    साथ ही, अपने टॉप-लेवल build.gradle में इन्हें जोड़ें:

    allprojects {
        ...
        // Required: you must exclude the Google Play service Maps SDK from
        // your transitive dependencies. This is to ensure there won't be
        // multiple copies of Google Maps SDK in your binary, as the Navigation
        // SDK already bundles the Google Maps SDK.
        configurations {
            implementation {
                exclude group: 'com.google.android.gms', module: 'play-services-maps'
            }
        }
    }
    

बिल्ड कॉन्फ़िगर करें

प्रोजेक्ट बनाने के बाद, आपके पास नेविगेशन SDK टूल बनाने और इस्तेमाल करने में मदद मिलती है.

स्थानीय प्रॉपर्टी अपडेट करें

  • Gradle Scripts फ़ोल्डर में, local.properties फ़ाइल खोलें और जोड़ें android.useDeprecatedNdk=true.

Gradle बिल्ड स्क्रिप्ट अपडेट करना

  • build.gradle (Module:app) फ़ाइल खोलें और इन कामों के लिए, इन दिशा-निर्देशों का पालन करें नेविगेशन SDK टूल की ज़रूरी शर्तें पूरी करने के लिए सेटिंग अपडेट करें और ऑप्टिमाइज़ेशन विकल्प सेट करने के बारे में भी सोचें.

    नेविगेशन SDK टूल के लिए ज़रूरी सेटिंग

    1. minSdkVersion को 23 या उससे ज़्यादा पर सेट करें.
    2. targetSdkVersion को 30 या उससे ज़्यादा पर सेट करें.
    3. ऐसी dexOptions सेटिंग जोड़ें जो javaMaxHeapSize को बढ़ाती हो.
    4. अतिरिक्त लाइब्रेरी के लिए जगह सेट करें.
    5. नेविगेशन SDK टूल के लिए repositories और dependencies जोड़ें.
    6. डिपेंडेंसी में मौजूद वर्शन नंबर को सबसे नए वर्शन से बदलें.

    बिल्ड में लगने वाले समय को कम करने के लिए वैकल्पिक सेटिंग

    • सक्षम करें कोड का छोटा होना और संसाधन का दायरा कम करना डिपेंडेंसी से इस्तेमाल न किए गए कोड और रिसॉर्स को हटाने के लिए, R8/ProGuard का इस्तेमाल करना. अगर R8/ProGuard चरण को चलाने में ज़्यादा समय लगता है, तो सक्षम करने के बारे में सोचें मल्टीडेक्स का इस्तेमाल करने के लिए प्रोत्साहित करते हैं.
    • बिल्ड में शामिल भाषाओं के अनुवाद की संख्या कम करें: सेट करें डेवलपमेंट के दौरान, एक भाषा के लिए resConfigs. फ़ाइनल बिल्ड के लिए, यह सेट करें आपने जिन भाषाओं का इस्तेमाल किया है उनके लिए resConfigs. डिफ़ॉल्ट रूप से, Gradle में नेविगेशन SDK टूल के साथ काम करने वाली सभी भाषाओं के लिए रिसॉर्स स्ट्रिंग.

नीचे, ऐप्लिकेशन के लिए Gradle बिल्ड स्क्रिप्ट का एक उदाहरण दिया गया है. सेटअप के निर्देश देखें सैंपल ऐप्लिकेशन, ताकि डिपेंडेंसी के अपडेट किए गए सेट का इस्तेमाल किया जा सके. आप जिस नेविगेशन SDK का इस्तेमाल कर रहे हैं वह थोड़ा आगे हो सकता है या देखें.

apply plugin: 'com.android.application'
apply plugin: 'com.google.cloud.artifactregistry.gradle-plugin'

ext {
    androidxVersion = "1.0.0"
    lifecycle_version = "1.1.1"
}

android {
    compileSdkVersion 30
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "<your id>"
        // Navigation SDK supports SDK 23 and later.
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        // Set this to the languages you actually use, otherwise you'll include resource strings
        // for all languages supported by the Navigation SDK.
        resConfigs "en"
        multiDexEnabled true
    }

    dexOptions {
        // This increases the amount of memory available to the dexer. This is required to build
        // apps using the Navigation SDK.
        javaMaxHeapSize "4g"
    }
    buildTypes {
        // Run ProGuard. Note that the Navigation SDK includes its own ProGuard configuration.
        // The configuration is included transitively by depending on the Navigation SDK.
        // If the ProGuard step takes too long, consider enabling multidex for development work
        // instead.
        all {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

// This tells Gradle where to look to find additional libraries - in this case, the
// google_navigation_navmap.aar file.
repositories {
    flatDir {
        dirs 'libs'
    }
    google()

    // Required for accessing the Navigation SDK on Google's Maven repository.
    maven {
        url "artifactregistry://us-west2-maven.pkg.dev/gmp-artifacts/transportation"
    }
}

dependencies {
    // Include the Google Navigation SDK
    implementation 'com.google.android.maps:navsdk:4.4.0'

    // The included AAR file under libs can be used instead of the Maven repository.
    // Uncomment the line below and comment out the previous dependency to use
    // the AAR file instead. Ensure that you add the AAR file to the libs directory.
    // implementation(name: 'google_navigation_navmap', ext: 'aar')

    // These dependencies are required for the Navigation SDK to function
    // properly at runtime.
    implementation 'org.chromium.net:cronet-fallback:69.3497.100'
    // Optional for Cronet users:
    // implementation 'org.chromium.net:cronet-api:69.3497.100'
    implementation 'androidx.appcompat:appcompat:${androidxVersion}'
    implementation 'androidx.cardview:cardview:${androidxVersion}'
    implementation 'com.google.android.material:material:${androidxVersion}'
    implementation 'androidx.mediarouter:mediarouter:${androidxVersion}'
    implementation 'androidx.preference:preference:${androidxVersion}'
    implementation 'androidx.recyclerview:recyclerview:${androidxVersion}'
    implementation 'androidx.legacy:legacy-support-v4:${androidxVersion}'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    implementation 'com.github.bumptech.glide:okhttp-integration:4.9.0'
    implementation 'android.arch.lifecycle:common-java8:$lifecycle_version'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.android.datatransport:transport-api:2.2.0'
    implementation 'com.google.android.datatransport:transport-backend-cct:2.2.0'
    implementation 'com.google.android.datatransport:transport-runtime:2.2.0'
    implementation 'joda-time:joda-time:2.9.9'
    annotationProcessor 'androidx.annotation:annotation:1.1.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}

अपने ऐप्लिकेशन में एपीआई पासकोड जोड़ना

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

इस टास्क को आसान बनाने के लिए, हमारा सुझाव है कि आप Android के लिए सीक्रेट ग्रेडल प्लग इन.

अपने 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 की जांच नहीं की गई है सिस्टम.
    NAV_API_KEY=YOUR_API_KEY
  6. फ़ाइल सेव करें.
  7. अपनी टॉप-लेवल डायरेक्ट्री में local.defaults.properties फ़ाइल बनाएं. फ़ोल्डर को secrets.properties फ़ाइल के रूप में चुनकर यह कोड जोड़ें.

    NAV_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 Navigation 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 {
        // Optionally specify a different file name containing your secrets.
        // The plugin defaults to "local.properties"
        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 {
        // Optionally specify a different file name containing your secrets.
        // The plugin defaults to "local.properties"
        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 के लिए नेविगेशन SDK का इस्तेमाल करते हैं, तो आपको अपने ऐप्लिकेशन के कानूनी नोटिस में, एट्रिब्यूशन टेक्स्ट और ओपन सोर्स लाइसेंस का इस्तेमाल करें सेक्शन में जाएं.

आपको यहां ज़रूरी एट्रिब्यूशन टेक्स्ट और ओपन सोर्स लाइसेंस, Android ZIP फ़ाइल के लिए नेविगेशन SDK टूल:

  • NOTICE.txt
  • LICENSES.txt