Firebase Crashlytics는 Crash만 기록할 수 있지만, Sentry를 이용하면 Crash는 물론, 개발자가 직접 기록한 이벤트 로그를 확인 할 수 있고 오류가 난 디바이스의 정보와 회원 정보까지 쉽게 파악이 가능하다. 그래서 이번 프로젝트에서는 Sentry를 한 번 이용 해 보기로 했다.
기본 세팅
먼저 Sentry에 가입하고, Sentry에서 안드로이드 프로젝트를 만든 후 다음과 같이 대시보드에 진입 할 수 있는 상태가 되어야한다. 이 절차는 간단하므로 빠르게 스-킵!

먼저 공식 문서(docs.sentry.io/platforms/android/)가 말하는 대로, 안드로이드 프로젝트에서 세팅을 해 주어야 한다.
// Make sure jcenter or mavenCentral is there. repositories { jcenter() // Or mavenCentral() } // Enable Java 1.8 source compatibility if you haven't yet. android { compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } } // Add Sentry's SDK as a dependency. dependencies { implementation 'io.sentry:sentry-android:3.1.0' }
그런다음 AndroidManifest.xml
에 다음과 같이 추가한다. 여기서 android:value
값은 프로젝트마다 달라서 교체 해 주어야하는데, 이 값은 Sentry에서 만든 프로젝트의 안드로이드 앱 Settings
에서 Client Keys > DSN
값이다.

AndroidManifest.xml
<application> <meta-data android:name="io.sentry.dsn" android:value="https://examplePublicKey@o0.ingest.sentry.io/0 example-org / example-project " /> </application>
이까지만 하면 Proguard를 사용하지 않는 프로젝트에서 자유롭게 Sentry를 사용할 수 있을 것이다. 하지만 프로가드를 사용한다면 조금 더 세팅이 필요하다.
Proguard 설정
build.gradle
build.gradle
에 다음과 같이 추가한다.
buildscript { repositories { mavenCentral() } dependencies { // https://github.com/getsentry/sentry-android-gradle-plugin/releases classpath 'io.sentry:sentry-android-gradle-plugin:1.7.35' } }
app/build.gradle
app/build.gradle
에 다음과 같이 추가한다.
plugins { ... id 'io.sentry.android.gradle' } sentry { autoProguardConfig true autoUpload true uploadNativeSymbols false includeNativeSources false } dependencies { ... implementation 'org.slf4j:slf4j-nop:1.7.25' }
프로가드 설정값을 Sentry에 전달하기 위해서 sentry-cli
를 이용한다. 만약 sentry-cli
가 설치되어있지 않아 진행이 안된다면 다운 후 다시 시도해보는 것을 추천한다. https://github.com/getsentry/sentry-cli 그다음에는 sentry.properties
라는걸 만들어 주어야하는데 아래와 같이 생겼다.
defaults.project=your-project defaults.org=your-org auth.token=YOUR_AUTH_TOKEN
defaults.project
의 값에 방금 만든 Sentry 프로젝트 이름을, defaults.org
에 Organization Slug
값을(Sentry 대시보드의 Settings에서 확인 가능하다.), auth.token
에는 토큰 값을 새로 만들어서 넣어주면된다. 토큰은 아래 사이트에서 생성할 수 있고, 그냥 기본 세팅으로 진행해도 된다.
- 토큰 생성하기: sentry.io/settings/account/api/auth-tokens/
이렇게 생성된 sentry.properties
는 안드로이드 프로젝트의 최상단에 하나, app/src/main/resources/
에 하나 총 2개 넣어주어야한다. 주의할 점은 경로가 app/src/main/res/sentry.properties
가 아니라 app/src/main/resources/sentry.properties
라는 것이다. 이게 제대로 세팅이 안된다면 빌드시 error: An organization slug is required (provide with --org) 라는 오류가 뜨면서 나처럼 삽질로 1시간을 뚝딱~해버리니 주의...

proguard-rules.pro
마지막으로, 프로가드에는 다음과 같은 규칙을 추가한다. 이렇게해서 bulid 하면 제대로 작동이 될 것이다.
# ================================== # Sentry # ================================== -keepattributes SourceFile, LineNumberTable, Annotation -dontwarn org.slf4j.** -dontwarn javax.** -keep class io.sentry.event.Event { *; }
'프로그래밍 > Android' 카테고리의 다른 글
[안드로이드] 패키지명(Package name)으로 앱 실행하기 (0) | 2021.01.18 |
---|---|
[안드로이드] Firebase Crashlytics 연동방법 (0) | 2021.01.15 |
[Kotlin/Java] 생년월일 기준으로 현재 만 나이 계산하기 (0) | 2021.01.11 |
[안드로이드] 주식 봉차트 그리기 (Drawing candle stick chart with MPAndroidChart Library Example) (0) | 2021.01.10 |
[안드로이드] 주식차트 그리기 (Drawing LineChart with MPAndroidChart, Differentiate line colors by limit line value) (2) | 2021.01.09 |