프로젝트 설정

이 가이드에는 Android 버전 5.0.0 이상의 Navigation SDK를 사용하기 위한 빌드 구성 요구사항이 나열되어 있습니다.

이 안내에서는 Android IDE가 설치되어 있고 Android 개발에 익숙하다고 가정합니다.

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

다음 요구사항은 Android 버전 5.0.0 이상의 Navigation SDK에 적용됩니다.

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

  • 앱은 다음과 같이 Android 버전을 지정해야 합니다.

    • target 버전이 Android 13 (API 수준 33) 이상이어야 합니다.
    • 최소 버전은 Android 6 (API 수준 23) 이상이어야 합니다.
  • Navigation SDK로 빌드된 앱을 실행하려면 Android 기기가 다음 요구사항을 충족해야 합니다.

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

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

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

설정 방법

  1. 원하는 웹브라우저에서 Cloud Console에 로그인하고 Cloud Console 프로젝트를 만듭니다.
  2. Android 스튜디오와 같은 IDE에서 Android 앱 개발 프로젝트를 만들고 패키지 이름을 기록합니다.
  3. Cloud 콘솔 프로젝트용 Navigation SDK에 대한 액세스 권한을 제공하려면 Google Maps Platform 담당자에게 문의하세요.
  4. 웹브라우저의 Cloud Console 대시보드에서 사용자 인증 정보를 만들어 제한사항이 있는 API 키를 생성합니다.
  5. API 키 페이지에서 애플리케이션 제한사항 영역의 Android 앱을 클릭합니다.
  6. 패키지 이름 및 디지털 지문 추가를 클릭한 다음 개발 프로젝트의 패키지 이름과 해당 키의 SHA-1 디지털 지문을 입력합니다.
  7. 저장을 클릭합니다.

프로젝트에 탐색 SDK 추가

Navigation SDK는 Maven을 통해 제공됩니다. 개발 프로젝트를 만든 후 다음 방법 중 하나를 사용하여 SDK를 프로젝트에 통합할 수 있습니다.

다음은 프로젝트에 Navigation SDK를 추가하는 가장 간단하고 권장되는 방법인 google() Maven 저장소를 사용합니다.

  1. Gradle 또는 Maven 구성에 다음 종속 항목을 추가하여 원하는 Android용 Navigation SDK 버전을 VERSION_NUMBER 자리표시자로 바꿉니다.

    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>
    

    지도 SDK를 사용하는 종속 항목이 있는 경우 지도 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 사용을 위한 설정을 구성할 수 있습니다.

지역 숙박 시설 업데이트

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

Gradle 빌드 스크립트 업데이트

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

    Navigation SDK의 필수 설정

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

    빌드 시간을 줄이기 위한 설정(선택사항)

    • R8/ProGuard를 사용하여 코드 축소 및 리소스 축소를 사용 설정하여 사용하지 않는 코드와 리소스를 종속 항목에서 삭제합니다. R8/ProGuard 단계를 실행하는 데 시간이 너무 오래 걸리는 경우 개발 작업에 멀티덱스를 사용 설정해 보세요.
    • 빌드에 포함되는 언어 번역 횟수 줄이기: 개발 중에 한 언어에 resConfigs를 설정합니다. 최종 빌드의 경우 실제로 사용하는 언어에 resConfigs를 설정합니다. 기본적으로 Gradle에는 탐색 SDK에서 지원하는 모든 언어의 리소스 문자열이 포함됩니다.

    Java8 지원을 위한 디슈가링 추가

    • Android Gradle 플러그인 4.0.0 이상을 사용하여 앱을 빌드하는 경우 플러그인은 여러 Java 8 언어 API를 사용하도록 지원을 확장합니다. 자세한 내용은 자바 8 디슈가링 지원을 참고하세요. 컴파일 및 종속 항목 옵션의 방법은 아래의 빌드 스크립트 스니펫 예를 참고하세요.

다음은 애플리케이션용 Gradle 빌드 스크립트의 예입니다. 사용 중인 Navigation SDK 버전이 이 문서보다 약간 앞서거나 뒤에 있을 수 있으므로 샘플 앱에서 업데이트된 종속 항목 세트를 확인하세요.

apply plugin: 'com.android.application'

ext {
    navSdk = "__NAVSDK_VERSION__"
}

android {
    compileSdk 33
    buildToolsVersion='28.0.3'

    defaultConfig {
        applicationId "<your id>"
        // Navigation SDK supports SDK 23 and later.
        minSdkVersion 23
        targetSdkVersion 33
        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 {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        // Sets Java compatibility to Java 8
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

repositories {
    // Navigation SDK for Android and other libraries are hosted on Google's Maven repository.
    google()
}

dependencies {
    // Include the Google Navigation SDK.
    // Note: remember to exclude Google play service Maps SDK from your transitive
    // dependencies to avoid duplicate copies of the Google Maps SDK.
    api "com.google.android.libraries.navigation:navigation:${navSdk}"

    // Declare other dependencies for your app here.

    annotationProcessor "androidx.annotation:annotation:1.7.0"
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.9'
}

앱에 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가 버전 제어 시스템에 체크인되는 데서 제외되었으므로 키를 이 파일에 저장합니다.
    MAPS_API_KEY=YOUR_API_KEY
  6. 파일을 저장합니다.
  7. 최상위 수준 디렉터리에서 secrets.properties 파일과 동일한 폴더에 local.defaults.properties 파일을 만든 후 다음 코드를 추가합니다.

    MAPS_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

Mobility 또는 Fleet Engine Deliveries 고객인 경우

Mobility 또는 Fleet Engine Deliveries 고객인 경우 Mobility 문서에서 결제에 대해 알아보세요. 거래 기록에 관한 자세한 내용은 결제 설정, 청구 가능 거래 기록, 보고, 청구 가능 거래 기록 (Android)을 참고하세요.