# 준비하기

{% hint style="danger" %}
0.20.0 미만 버전은 일정 시간이 지난 후 지원이 종료될 수 있습니다. 0.20.0 이상 버전으로 업그레이드를 권장합니다.
{% endhint %}

## 사전 준비 <a href="#preparation" id="preparation"></a>

‌아이나비 지도 SDK를 사용하기 위해서는 인증을 위한 **APP KEY**가 필요합니다.‌

### 서비스 활성화 및 APP KEY 발급

* **APP KEY** 발급을 위해서는 [**iMPS**](https://mapsapi.inavisys.com/) 계정이 필요합니다. 계정이 없다면 먼저 계정을 생성해주세요.
* [**iMPS Console**](https://mapsapi.inavisys.com/dash-board/) 에서 APP을 생성합니다.
* 생성된 APP에서 상품을 신청을 신청하시면, **APP KEY**를 확인할 수 있습니다.

## Android Studio 프로젝트 환경 구성 <a href="#project-settings" id="project-settings"></a>

아이나비 지도 SDK는 별도 저장소를 통해 배포되므로, 다음과 같이 프로젝트 및 앱 모듈 레벨의 **build.gradle** 파일에 저장소 설정과 아이나비 지도 SDK에 대한 의존성을 추가합니다.

```groovy
/* Root Project build.gradle */
allprojects {
    repositories {
        google()
        ...
        // 아이나비 지도 저장소
        maven { url 'https://repo.inavi.com/artifactory/maps' }
    }
}
```

```groovy
/* App Module build.gradle */
dependencies {
    implementation 'com.inavi.mapsdk:inavi-maps-sdk:0.22.0'
}
```

## 난독화 설정 <a href="#app-key-settings" id="app-key-settings"></a>

R8/ProGuard를 사용하는 릴리스 빌드에서는 iNavi Maps SDK 관련 클래스 보존을 위해 아래 규칙을 proguard-rules.pro 또는 consumer-rules.pro에 필수로 추가해야 합니다.

```
-keep class com.inavi.mapsdk.** { *; }
-dontwarn com.inavi.mapsdk.**
```

## APP KEY 설정 <a href="#app-key-settings" id="app-key-settings"></a>

발급받은 **APP KEY**를 설정할 수 있도록 아래의 두 가지 방법을 제공합니다.&#x20;

{% hint style="danger" %}
**APP KEY**가 설정되지 않으면 지도 초기화 단계에서 인증 오류가 발생합니다.
{% endhint %}

### AndroidManifest.xml에서 설정

**AndroidManifest.xml**에 다음과 같이 `<meta-data>`를 추가하여 **APP KEY**를 설정할 수 있습니다.

```markup
<!-- AndroidManifext.xml -->
<manifest>
    <application>
        <meta-data
            android:name="com.inavi.mapsdk.AppKey"
            android:value="YOUR_APP_KEY" />
    </application>
</manifest>
```

### InaviMapSdk API 호출로 설정

Application 생성 시점에 동적으로 [`InaviMapSdk`](https://inavi-systems.github.io/inavi-maps-sdk-reference/android/com/inavi/mapsdk/maps/InaviMapSdk.html) 싱글턴 객체의 함수를 호출하여 **APP KEY**를 설정할 수 있습니다.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
InaviMapSdk.getInstance(context).appKey = "YOUR_APP_KEY"
```

{% endtab %}
{% endtabs %}

## **인증 실패 처리** <a href="#auth-failure-handling" id="auth-failure-handling"></a>

지도 초기화 단계에서 인증을 실패하면 SDK 내부에 등록된 콜백 함수로 에러 코드와 메시지를 전달합니다.\
인증 실패에 대한 이벤트를 처리하려면 [`InaviMapSdk`](https://inavi-systems.github.io/inavi-maps-sdk-reference/android/com/inavi/mapsdk/maps/InaviMapSdk.html) 싱글턴 객체의 [`authFailureCallback`](https://inavi-systems.github.io/inavi-maps-sdk-reference/android/com/inavi/mapsdk/maps/InaviMapSdk.html#setAuthFailureCallback-com.inavi.mapsdk.maps.InaviMapSdk.AuthFailureCallback-) 속성을 아래와 같이 설정해야 합니다.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
InaviMapSdk.getInstance(context).authFailureCallback =
    InaviMapSdk.AuthFailureCallback { errCode: Int, msg: String ->
        // 인증 실패 처리
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
`authFailureCallback` 속성을 별도로 설정하지 않으면 기본적으로 에러 코드와 메시지가 팝업 형태로 표출됩니다.
{% endhint %}

### **인증 에러 코드** <a href="#auth-error-code" id="auth-error-code"></a>

| Code | Description |
| ---- | ----------- |
| 300  | 앱키 인증 오류    |
| 401  | 앱키 설정되지 않음  |
| 503  | 서버 연결 실패    |
| 504  | 서버 연결 시간 초과 |
| 500  | 알 수 없는 에러   |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://inavimaps-android.gitbook.io/sdkguide/guide/get-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
