페이지 이동경로
  • Docs>
  • Android>
  • Getting started

Android

Getting started

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

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.

Modules

Kotlin
RxKotlin
Module Description
v2-common Common module that contains essential elements
v2-auth Authentication
v2-user Kakao Login, User Management
v2-share Kakao Talk Sharing
v2-talk Kakao Talk Social, Kakao Talk Messaging
v2-template Message template
v2-navi Kakao Navi
v2-friend Friend picker
v2-cert Kakao Certificate
Module Description
v2-common Common module that contains essential elements
v2-auth-rx Authentication
v2-user-rx Kakao Login, User Management
v2-share-rx Kakao Talk Sharing
v2-talk-rx Kakao Talk Social, Kakao Talk Messaging
v2-friend-rx Module for picker
Note: 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

Platform

Set Android app information on [My Application] > [Platform]. Refer to Platform.

Key hashes

Key hashes are the values hashed from the certificate fingerprints of the certificate and used to check if the app is malicious and the updates or changes are from the original app. The API server checks if the key hash added to the request matches the value specified in [My Application] > [Platform] for identification. Key hash has two types.

  • Debug key hash is generated from a Debug certificate that is automatically generated from Android Studio when running or debugging.
  • Release key hash is generated from a Release certificate to release the app to the store.

Check the key hashes in one of the ways below. Register all of the key hashes in [My Application] > [Platform] > [Android]. Refer to Platforms.

Caution: When registering key hashes

Make sure to add all debug key hashes by development environments and a release key hash. Kakao API calls are not allowed to apps without key hashes. If several developers participate in developing an app, register all debug key hashes that each developer has because they have all different debug key hashes depending on development environments.

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
Mac
Windows
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android | openssl sha1 -binary | openssl base64
keytool -exportcert -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore -storepass android -keypass android | openssl sha1 -binary | openssl base64
Release key hash
Mac
Windows
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | PATH_TO_OPENSSL_LIBRARY\bin\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 

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

Java 8 features

To use the Java 8 features, add the following settings to the build.gradle(module-level) file. Refer to the official site for Android app developers for more details.

// Use Java 8 features

android {

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    // For Kotlin projects
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
Screenshot of setting Java version 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>; }
-keep class * extends com.google.gson.TypeAdapter

# https://github.com/square/okhttp/pull/6792
-dontwarn org.bouncycastle.jsse.**
-dontwarn org.conscrypt.*
-dontwarn org.openjsse.**

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.

  • build.gradle(project-level): Android Studio Artic Fox or lower
  • settings.gradle(project-level): Android Studio Artic Fox or higher

Refer to the image below for information on how to distinguish project-level files.

build.gradle screen
build.gradle
// Allprojects not available in the latest Android Studio
allprojects {    
    repositories {        
        google()        
        jcenter()        
        maven { url 'https://devrepo.kakao.com/nexus/content/groups/public/'}    
    }
}
settings.gradle
dependencyResolutionManagement {    
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)    
        repositories {        
            google()        
            mavenCentral()        
            maven { url 'https://devrepo.kakao.com/nexus/content/groups/public/' }    
    }
}

Add modules

To use the Kakao APIs, add the desired modules to the build.gradle(module-level) file.

Kotlin
RxKotlin
dependencies {
  implementation "com.kakao.sdk:v2-all:2.18.0" // Add all modules (Available in 2.11.0 or higher)

  implementation "com.kakao.sdk:v2-user:2.18.0" // Kakao Login
  implementation "com.kakao.sdk:v2-talk:2.18.0" // Kakao Talk Social, Kakao Talk Messaging
  implementation "com.kakao.sdk:v2-friend:2.18.0" // Friend picker
  implementation "com.kakao.sdk:v2-share:2.18.0" // Kakao Talk Sharing
  implementation "com.kakao.sdk:v2-navi:2.18.0" // Kakao Navi 
  implementation "com.kakao.sdk:v2-cert:2.18.0" // Kakao Certificate
}
dependencies {
  implementation "com.kakao.sdk:v2-all-rx:2.18.0" // Add all modules (Available in 2.11.0 or higher)

  implementation "com.kakao.sdk:v2-user-rx:2.18.0" // Kakao Login
  implementation "com.kakao.sdk:v2-talk-rx:2.18.0" // Kakao Talk Social, Kakao Talk Messaging
  implementation "com.kakao.sdk:v2-friend-rx:2.18.0" // Friend picker
  implementation "com.kakao.sdk:v2-share-rx:2.18.0" // Kakao Talk Sharing
  implementation "com.kakao.sdk:v2-navi:2.18.0" // Kakao Navi
  implementation "com.kakao.sdk:v2-cert:2.18.0" // Kakao Certificate
}

Initialize

After installing the SDK, initialize the SDK for initial setup.

Initialize the KakaoSDK instance by adding the init method in the Application instance with your Native app key.

class GlobalApplication : Application() {
  override fun onCreate() {
    super.onCreate()
    // Other codes for initialization 

    // Initialize Android SDK 
    KakaoSdk.init(this, "${YOUR_NATIVE_APP_KEY}")
  }
}