프로젝트 설정 -- 버전 4.99 이하

이 가이드에는 Android용 Navigation SDK 안내에서는 Android IDE가 있다고 가정합니다. Android 개발에 익숙해야 합니다.

Navigation SDK 사용을 위한 최소 요구사항

이 요구사항은 Android용 Navigation SDK 버전 4.99 이하에 적용됩니다.

  • Navigation SDK가 사용 설정된 Google Cloud 콘솔 프로젝트 프로비저닝은 Google Maps Platform 담당자에게 문의하세요.

  • 앱은 API 수준 30 이상을 타겟팅해야 합니다.

  • Navigation SDK로 빌드된 앱을 실행하려면 Android에서 기기에 Google Play 서비스가 있어야 함 사용 설정할 수 있습니다

  • 저작자 표시 및 라이선스 텍스트 앱에 추가해야 합니다.

프로젝트 설정: Cloud 콘솔 프로젝트 및 Android 프로젝트

앱을 빌드하거나 테스트하려면 먼저 Cloud 콘솔 프로젝트를 만들어야 합니다. API 키 사용자 인증 정보를 추가합니다 프로젝트에 액세스하려면 프로젝트에 프로비저닝이 있어야 합니다. Navigation SDK를 지원합니다. Cloud 콘솔 프로젝트 내의 모든 키 Navigation SDK에 대한 동일한 액세스 권한이 부여됩니다. 키 둘 이상의 개발 프로젝트가 연결될 수 있습니다. 이미 콘솔 프로젝트가 있다면 현재 프로젝트에 키를 추가할 수 있습니다.

설정 방법

  1. 원하는 웹브라우저에서 Cloud 콘솔로 이동하여 Cloud 콘솔 살펴보겠습니다
  2. IDE(예: Android 스튜디오)에서 Android 앱 개발을 만듭니다. 확인하고 패키지 이름을 기록해 둡니다.
  3. Google Maps Platform 담당자에게 문의하여 Cloud 콘솔용 Navigation SDK 살펴보겠습니다
  4. 웹브라우저의 Cloud Console 대시보드에서 사용자 인증 정보를 만들어 제한사항이 있는 API 키를 생성합니다.
  5. API 키 페이지애플리케이션 제한사항에서 Android 앱을 클릭합니다. 영역입니다.
  6. 패키지 이름 및 디지털 지문 추가를 클릭한 다음 패키지를 입력합니다. SHA-1 디지털 지문이 포함될 수 있습니다.
  7. 저장을 클릭합니다.

프로젝트에 Navigation SDK 추가

Navigation SDK는 Maven을 통해 또는 AAR 번들. 개발 프로젝트를 생성한 후 다음 방법으로 SDK를 프로젝트에 통합할 수 있습니다. 다음 방법 중 하나를 사용합니다.

다음은 가장 간단한 google() Maven 저장소를 사용합니다. 탐색 SDK를 추가하는 권장 방법은 프로젝트

  1. Gradle 또는 Maven 구성에 다음 종속 항목을 추가합니다. VERSION_NUMBER 자리표시자를 원하는 버전의 Android용 Navigation SDK를 사용해야 합니다.

    Gradle

    모듈 수준 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 이전의 Navigation SDK에 Maven 사용 또는 Driver SDK와 함께 사용

Navigation SDK는 v4 버전에서 확인할 수 있습니다. 이것은 동일한 라이브러리에 위의 버전과 같은 업데이트가 모두 포함되고, 전환 중 드라이버 SDK 및 기타 라이브러리와의 호환성 사용 이 종속 항목을 사용하려면 다음과 같은 경우 gcloud를 통해 클라우드 프로젝트에 로그인해야 합니다. 있습니다.

  1. 다음에 설명된 대로 Google Maven 저장소에 액세스하도록 환경을 설정합니다. 기본 요건 소비자 SDK 문서의 섹션에 나와 있습니다. Navigation SDK는 작업공간 그룹을 통해 제어됩니다.
  2. Gradle 또는 Maven 구성에 다음 종속 항목을 추가하고 원하는 Navigation SDK 버전의 VERSION_NUMBER 자리표시자

    Gradle

    모듈 수준 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>
    

Navigation SDK는 AAR 번들로도 제공됩니다. 개발 프로젝트를 만든 후에 SDK를 통합할 수 있습니다. 이 안내 IDE에 Android 스튜디오를 사용한다고 가정합니다.

  1. Navigation SDK의 최신 버전 다운로드 공유 Google Drive에서 다운로드한 후 압축을 풉니다. 만약 액세스 권한이 없는 경우 담당자에게 문의하세요.

  2. Android 스튜디오에서 프로젝트를 열고 Google Play 서비스 패키지를 추가합니다. SDK Manager를 사용하여 앱의 SDK를 관리할 수 있습니다

  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'
            }
        }
    }
    

빌드 구성

프로젝트를 생성한 후에는 해당 프로젝트의 설정을 구성할 수 있습니다. Navigation SDK를 사용하는 방법을 설명합니다.

로컬 숙박 시설 업데이트

  • Gradle Scripts 폴더에서 local.properties 파일을 열고 android.useDeprecatedNdk=true입니다.

Gradle 빌드 스크립트 업데이트

  • build.gradle (Module:app) 파일을 열고 다음 가이드라인에 따라 Navigation SDK의 요구사항을 충족하도록 설정 업데이트 최적화 옵션을 설정하는 것도 고려해 보세요.

    Navigation SDK의 필수 설정

    1. minSdkVersion를 23 이상으로 설정합니다.
    2. targetSdkVersion를 30 이상으로 설정합니다.
    3. javaMaxHeapSize를 늘리는 dexOptions 설정을 추가합니다.
    4. 추가 라이브러리의 위치를 설정합니다.
    5. Navigation SDK의 repositoriesdependencies를 추가합니다.
    6. 종속 항목의 버전 번호를 사용 가능한 최신 버전으로 바꿉니다.

    빌드 시간을 줄이기 위한 선택적 설정

    • 사용 코드 축소와 리소스 축소 R8/ProGuard를 사용하여 종속 항목에서 사용하지 않는 코드와 리소스를 삭제합니다. R8/ProGuard 단계를 실행하는 데 시간이 너무 오래 걸리면 멀티덱스 개발 작업에 사용할 수 있습니다
    • 빌드에 포함된 언어 번역 수를 줄입니다. 개발 중에는 1개 언어에 resConfigs를 사용합니다. 최종 빌드의 경우 resConfigs: 실제로 사용하는 언어의 경우 기본적으로 Gradle에는 Navigation SDK에서 지원하는 모든 언어의 리소스 문자열입니다.

다음은 애플리케이션의 Gradle 빌드 스크립트의 예입니다. 자세한 내용은 업데이트된 종속 항목 집합을 위한 샘플 앱을 사용 중인 Navigation 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'
}

앱에 API 키 추가

이 섹션에서는 앱이 더욱 안전하게 참조할 수 있도록 API 키를 저장하는 방법을 설명합니다. API 키는 버전 제어 시스템에 체크인하면 안 되며, 프로젝트의 루트 디렉터리에 있는 secrets.properties 파일에 저장하는 것이 좋습니다. secrets.properties 파일에 관한 자세한 내용은 Gradle 속성 파일을 참고하세요.

이 작업을 간소화하려면 Android용 Secrets Gradle 플러그인을 사용하는 것이 좋습니다.

Google 지도 프로젝트에 Android용 Secrets Gradle 플러그인을 설치하려면 다음 단계를 따르세요.

  1. Android 스튜디오에서 최상위 수준 build.gradle 또는 build.gradle.kts 파일을 열고 다음 코드를 buildscript 아래 dependencies 요소에 추가합니다.

    Groovy

    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 요소에 다음 코드를 추가합니다.

    Groovy

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

    Kotlin

    plugins {
        id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
    }
  3. 모듈 수준 build.gradle 파일에서 targetSdkcompileSdk를 34로 설정해야 합니다.
  4. 파일을 저장하고 프로젝트를 Gradle과 동기화합니다.
  5. 최상위 수준 디렉터리에서 secrets.properties 파일을 연 후 다음 코드를 추가합니다. YOUR_API_KEY를 직접 생성한 API 키로 변경합니다. secrets.properties가 버전 제어 시스템에 체크인되는 데서 제외되었으므로 키를 이 파일에 저장합니다.
    NAV_API_KEY=YOUR_API_KEY
  6. 파일을 저장합니다.
  7. 최상위 수준 디렉터리에서 secrets.properties 파일과 동일한 폴더에 local.defaults.properties 파일을 만든 후 다음 코드를 추가합니다.

    NAV_API_KEY=DEFAULT_API_KEY

    이 파일의 목적은 secrets.properties 파일이 없는 경우 빌드에 실패하지 않도록 API 키의 백업 위치를 제공하는 것입니다. 이는 버전 제어 시스템에서 secrets.properties가 빠진 앱을 복제하거나 API 키를 제공하는 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용 Navigation SDK를 사용하는 경우 앱 법적 고지에 포함된 저작자 표시 텍스트 및 오픈소스 라이선스 섹션으로 이동합니다.

필요한 저작자 표시 텍스트와 오픈소스 라이선스는 다음 페이지에서 확인할 수 있습니다. Android용 Navigation SDK ZIP 파일:

  • NOTICE.txt
  • LICENSES.txt