본문 바로가기메인 메뉴 바로가기사이드 메뉴 바로가기

kakao developers

Related sites
  • Docs
  • Android
  • Getting started

사이드 메뉴

Kakao Map

Search

Android

Getting started

This document guides how to use the Kakao SDK for Android("Android SDK") provided by the Kakao Developers.

Before you begin

Requirements

  • Android Studio 3.6.1 or higher
  • API 23: Android 6.0 (Marshmallow) or higher
Note: External library dependency

The Android SDK uses the following libraries that are automatically installed when installing the Android SDK.

Platform

Set the Android app information in [App] > [Platform key] > [Native app key] on the app management page. For details, see Native app key.

Key hashes

A key hash is a hashed value of the certificate’s certificate fingerprints, used to determine whether an app is malicious. When the Kakao API is invoked, the Kakao API server checks whether the key hash added to the request header matches the value registered on the Kakao platform. There are two types of key hashes: a debug key hash and a release key hash.

  • Debug key hash: A value hashed from the debug certificate automatically generated by Android Studio according to the development environment when the project is first created or debugged.
  • Release key hash: A value hashed from the release certificate created for distributing the app to an app store.

Check both the debug and release key hash values using the methods below, then register them in [App] > [Platform key] > [Native app key] on the app management page. For details, see Native app key.

When registering key hashes

  • Add all debug key hashes for each development environment.
  • Add the release key hash.
  • Kakao API calls will fail if the app does not have the necessary key hashes registered.
  • If multiple developers are working on the app, register every developer's debug key hash, as they differ depending on each developer’s environment.

Using Terminal to generate Debug and Release key hashes

To get key hashes using Terminal, Keytool program, key and certificate management tool are required. On Windows, download OpenSSL for Windows libraries is required. On Mac, Keytool is installed.

Run the command in Command Prompt according to the operating system.

Debug key hash
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android | openssl sha1 -binary | openssl base64
Release key hash
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

Using Kakao SDK to get Debug and Release key hashes

Call the getKeyHash() method provided in Utility through the Android SDK.

import com.kakao.sdk.common.util.Utility
var keyHash = Utility.getKeyHash(this)

Using the Google Play Console to get Release key hash

With Google Play App Signing, use the SHA-1 certificate fingerprint obtained on the Google Play Console, not generating a Release key hash on the Terminal. Refer to Play Console Help > Use Play App Signing for more details.

In the Google Play Console, select [Release Management] > [App Signing], and then copy the value of SHA-1 certificate fingerprint. Refer to Use Play App Signing.

keytool -printcert -file ./deployment_cert.der

Run the following command in Terminal with the SHA-1 certificate fingerprint value obtained.

echo "{SHA-1_CERTIFICATE_FINGERPRINT}" | xxd -r -p | openssl base64

Sample app

Kakao Developers provides a sample app that allows you to quickly check the main features of the Android SDK. With the sample app, you can directly test SDK features such as Kakao Login and Kakao Talk Share, and review sample implementation code.

Usage guide

This section describes how to run the Android SDK sample app.

  1. Download the Android SDK sample app from Download.
  2. Refer to Key hash to generate the debug key hash for the sample app project.
  3. Register the generated key hash in [Android SDK sample app] on the Account settings page.
    • The key hash registered for the sample app is used to validate sample app requests.
    • If the sample app key hash is missing or incorrectly registered, a KOE009 or 401 error occurs.
  4. You can run the sample app to test the key features of the Android SDK and review the implementation example code.

Project settings

Internet permission

Allow internet permission to communicate with the Kakao Sever through the Kakao APIs.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sample">
<!-- Allow Internet permission -->
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
...

Screenshot of allowing internet permission in Android Studio

Optional: ProGuard rules

To enable shrinking, obfuscation, and optimization when building the release version of the app, add the following codes in the ProGuard rules file to exclude the Kakao SDK from shrinking and obfuscation.

-keep class com.kakao.sdk.**.model.* { <fields>; }
# https://github.com/square/okhttp/pull/6792
-dontwarn org.bouncycastle.jsse.**
-dontwarn org.conscrypt.*
-dontwarn org.openjsse.**
# refrofit2 (with r8 full mode)
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>
-keep,allowobfuscation,allowshrinking class retrofit2.Response

Install

Set Gradle

Set Gradle by declaring a Maven repository to sync the project with the Android SDK. Depending on the version of Android Studio, the file to declare repositories is different. Refer to Dependency management in Gradle for more details.

settings.gradle.kts
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url = java.net.URI("https://devrepo.kakao.com/nexus/content/groups/public/") }
}
}

Add modules

Add the required modules to the build.gradle.kts file at the module level. You can add either all modules or only the required ones.

dependencies {
implementation("com.kakao.sdk:v2-all:${LATEST_VERSION}") // Add all modules (Available in 2.11.0 or higher)
implementation("com.kakao.sdk:v2-user:${LATEST_VERSION}") // Module for the Kakao Login APIs
implementation("com.kakao.sdk:v2-share:${LATEST_VERSION}") // Module for the Kakao Talk Share APIs
implementation("com.kakao.sdk:v2-talk:${LATEST_VERSION}") // Module for the Kakao Talk Channel, Kakao Talk Social, Kakao Talk Message APIs
implementation("com.kakao.sdk:v2-friend:${LATEST_VERSION}") // Module for the picker APIs
implementation("com.kakao.sdk:v2-navi:${LATEST_VERSION}") // Module for the Kakao Navi APIs
implementation("com.kakao.sdk:v2-cert:${LATEST_VERSION}") // Module for the Kakao Certification APIs
}

Initialize

To use the Android SDK, install and then initialize it by including the app’s Native app key in the init() method. The Native app key can be found in [App] > [Platform key] > [Native app key] on the app management page.

If you are using a class that extends Application, you can initialize it as shown below.

class GlobalApplication : Application() {
override fun onCreate() {
super.onCreate()
// Other codes for initialization
// Initialize Android SDK
KakaoSdk.init(this, "${YOUR_NATIVE_APP_KEY}")
}
}

You must also set the name of the class that performs Kakao SDK initialization in the application of AndroidManifest.xml. In the example above, initialization was done in the GlobalApplication class, so add the same name in the settings as shown below.

<application
<!-- android:name setting -->
android:name=".GlobalApplication"
<!-- ... -->
>

Module information

Provided modules and main features

The modules and main features of Android SDK are below.

ModuleClientDescription
v2-common-Common module for essential elements

Main features: Initialize
v2-authAuthApiClientModule for the authentication and token management through Kakao Login

Main features: Check token presence API
v2-userUserApiClientModule for the Kakao Login APIs

Main features: Kakao Login API, Retrieve user information API
v2-shareShareClientModule for the Kakao Talk Share APIs

Main features: Send message with custom template API
v2-talkTalkApiClientModule for the Kakao Talk Channel, Kakao Talk Social, Kakao Talk Message APIs

Main features: Follow Kakao Talk Channel API
v2-template-Module for message templates
v2-friendPickerClientModule for the picker APIs

Main features: Retrieve friends through picker API
v2-naviNaviClientModule for the Kakao Navi APIs
v2-certCertApiClientModule for the Kakao Certification APIs

Module dependency

Some modules in the Kakao SDK are dependent on another module. Each subordinate module is automatically added together.

Kakao SDK module dependency tree

Was this helpful?