콘텐츠로 이동
시작하기

Android Setup

SDK 연동을 위한 사전 준비 및 설정

아래 항목을 eng@fairytech.ai로 전달해 주시면, 프로젝트 설정 후에 고객사에 맞는 SDK 설치값을 회신드립니다.

  • 개발용 인증서 SHA-1 키해시 및 앱 패키지명
  • 배포용 인증서 SHA-1 키해시 및 앱 패키지명
  • (FCM 혹은 캐시백 이용시) 푸쉬 알림 설정을 위한 service account key.json

프로젝트 루트에서 다음 명령을 실행하면 빌드 variant별 SHA-1을 확인할 수 있습니다.

Terminal window
./gradlew signingReport

출력에서 대상 variant의 SHA1을 확인하고, 해당 앱 패키지명과 함께 전달해 주세요. 자세한 내용은 Google의 클라이언트 인증 가이드를 참고하세요.

플레이스홀더 입력할 값
{SDK_ARTIFACT_ID} 연동 구성에 따라 Fairy에서 제공한 SDK artifact ID. 예: moment-x, moment-x-push
{SDK_VERSION} Fairy에서 제공한 SDK 버전. 예: 2.0.2
{MAVEN_SECRET} Fairy에서 제공한 Maven Secret Key
{PROJECT_ID} Fairy에서 제공한 프로젝트 식별자
{SDK_API_KEY} Fairy에서 제공한 Moment SDK 초기화용 API Key

settings.gradle 또는 build.gradle 에 MomentSDK를 다운로드 받을 maven repository를 추가해주세요.

// 1) maven repository 추가
repositories {
maven {
url "https://asia-northeast3-maven.pkg.dev/moment-prod-16047/moment-x"
// Fairy에서 제공한 Maven Secret Key를 입력합니다.
credentials {
username = "_json_key_base64"
password = "{MAVEN_SECRET}"
}
authentication {
basic(BasicAuthentication)
}
}
}

build.gradle 에 moment dependency를 추가해주세요. 추가 후 Sync Project with Gradle Files 를 실행해 dependency가 다운로드 되는지 확인해주세요.

dependencies {
implementation "ai.fairytech:{SDK_ARTIFACT_ID}:{SDK_VERSION}"
}

AndroidManifest.xmlPROJECT_ID, API_KEY를 추가해주세요.

<application ...>
<meta-data
android:name="ai.fairytech.moment.PROJECT_ID"
android:value="{PROJECT_ID}" />
<meta-data
android:name="ai.fairytech.moment.API_KEY"
android:value="{SDK_API_KEY}" />
</application>
-keep class ai.fairytech.moment.** { *; }
-keep interface ai.fairytech.moment.** { *; }

앱 시작 시점에 SDK를 초기화합니다. Application#onCreate 에서 호출합니다.

class MyApp : Application() {
override fun onCreate() {
super.onCreate()
Moment.initialize(this)
}
}

Moment 서비스를 시작하기 전, 실행에 필요한 config를 설정합니다. (스타터내 예시 코드)

// Kotlin
val config = MomentSDK.Config(applicationContext)
// SDK 알림을 표시할 때 사용할 호스트 앱의 알림 채널 ID
.notificationChannelId(NotificationController.NOTIFICATION_CHANNEL_ID)
// SDK 알림에 사용할 ID
// 호스트 앱의 다른 알림 ID와 충돌하지 않는 0 이상의 값 사용
.notificationId(NotificationController.NOTIFICATION_ID)
// 호스트 앱에서 사용하는 알림용 small icon drawable 리소스
.notificationIconResId(R.drawable.baseline_person_24)
// 포그라운드 서비스 알림에 사용할 채널 ID
.serviceNotificationChannelId(NotificationController.SERVICE_NOTIFICATION_CHANNEL_ID)
// 포그라운드 서비스 알림에 사용할 ID
// 호스트 앱의 다른 알림 ID와 충돌하지 않는 0 이상의 값 사용
.serviceNotificationId(NotificationController.SERVICE_NOTIFICATION_ID)
// 포그라운드 서비스 알림에 표시할 small icon drawable 리소스
.serviceNotificationIconResId(R.drawable.baseline_person_24)
// 포그라운드 서비스 알림의 제목과 내용이며 생략 가능
// .serviceNotificationTitle("인식 서비스")
// .serviceNotificationText("인식 서비스가 동작 중입니다")
// Java
MomentSDK.Config config = new MomentSDK.Config(applicationContext)
// SDK 알림을 표시할 때 사용할 호스트 앱의 알림 채널 ID
.notificationChannelId(NotificationController.NOTIFICATION_CHANNEL_ID)
// SDK 알림에 사용할 ID
// 호스트 앱의 다른 알림 ID와 충돌하지 않는 0 이상의 값 사용
.notificationId(NotificationController.NOTIFICATION_ID)
// 호스트 앱에서 사용하는 알림용 small icon drawable 리소스
.notificationIconResId(R.drawable.baseline_person_24)
// 포그라운드 서비스 알림에 사용할 채널 ID
.serviceNotificationChannelId(NotificationController.SERVICE_NOTIFICATION_CHANNEL_ID)
// 포그라운드 서비스 알림에 사용할 ID
// 호스트 앱의 다른 알림 ID와 충돌하지 않는 0 이상의 값 사용
.serviceNotificationId(NotificationController.SERVICE_NOTIFICATION_ID)
// 포그라운드 서비스 알림에 표시할 small icon drawable 리소스
.serviceNotificationIconResId(R.drawable.baseline_person_24);
// 포그라운드 서비스 알림의 제목과 내용이며 생략 가능
// config.serviceNotificationTitle("인식 서비스");
// config.serviceNotificationText("인식 서비스가 동작 중입니다");