-
-
Notifications
You must be signed in to change notification settings - Fork 471
chore(android-sqlite): Add SQLite samples to sentry-samples-android #5504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/support-sqlite-driver
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Sentry Sample Android App | ||
|
|
||
| Sample application demonstrating how to use the Sentry Android SDK, including core functionality (error reporting, tracing, session replay, profiling) and integrations (Compose, OkHttp, SQLDelight, etc.). | ||
|
|
||
| ## How to run it? | ||
|
|
||
| Install the app on your device or emulator: | ||
|
|
||
| ``` | ||
| ./gradlew :sentry-samples:sentry-samples-android:installDebug | ||
| ``` | ||
|
|
||
| or simply open the project in Android Studio and run the `sentry-samples-android` configuration. | ||
|
|
||
| ## Viewing events locally | ||
|
|
||
| Debug builds enable SDK debug logging, so captured envelopes are printed to logcat (tag `Sentry`): | ||
|
|
||
| ``` | ||
| adb logcat -s Sentry | ||
| ``` | ||
|
|
||
| ## Viewing events on Sentry UI | ||
|
|
||
| By default, events appear under the [sentry-sdk test project](https://sentry-sdks.sentry.io/issues/?project=5428559). | ||
| To redirect them to your own project, replace the test DSN (i.e., the `io.sentry.dsn` `meta-data` value) | ||
| in `src/main/AndroidManifest.xml` with your own. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ plugins { | |
| id("com.android.application") | ||
| alias(libs.plugins.kotlin.android) | ||
| alias(libs.plugins.kotlin.compose) | ||
| alias(libs.plugins.ksp) | ||
| alias(libs.plugins.sqldelight) | ||
| } | ||
|
|
||
| android { | ||
|
|
@@ -15,7 +17,8 @@ android { | |
|
|
||
| defaultConfig { | ||
| applicationId = "io.sentry.samples.android" | ||
| minSdk = libs.versions.minSdk.get().toInt() | ||
| // androidx.sqlite 2.6+ require minSdk 23; the Sentry SDK still supports 21. | ||
| minSdk = 23 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that Room 3 requires us to bump the Android sample app minSDK to 23 and JVM target to 11. |
||
| targetSdk = libs.versions.targetSdk.get().toInt() | ||
| versionCode = 2 | ||
| versionName = project.version.toString() | ||
|
|
@@ -90,7 +93,13 @@ android { | |
| } | ||
| } | ||
|
|
||
| kotlin { compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8 } | ||
| // Java 11 b/c androidx.room3 requires it. | ||
| compileOptions { | ||
| sourceCompatibility = JavaVersion.VERSION_11 | ||
| targetCompatibility = JavaVersion.VERSION_11 | ||
| } | ||
|
|
||
| kotlin { compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11 } | ||
|
|
||
| androidComponents.beforeVariants { | ||
| it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType) | ||
|
|
@@ -116,13 +125,25 @@ android { | |
| @Suppress("UnstableApiUsage") packagingOptions { jniLibs { useLegacyPackaging = true } } | ||
| } | ||
|
|
||
| sqldelight { | ||
| databases { | ||
| create("SampleSQLDelightDatabase") { | ||
| packageName.set("io.sentry.samples.android.sqlite") | ||
| // Keep .sq files next to the hand-written Kotlin (src/main/java/.../sqlite) instead of the | ||
| // default src/main/sqldelight source root. | ||
| srcDirs("src/main/java") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation( | ||
| kotlin(Config.kotlinStdLib, org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION) | ||
| ) | ||
|
|
||
| implementation(projects.sentryAndroid) | ||
| implementation(projects.sentryAndroidFragment) | ||
| implementation(projects.sentryAndroidSqlite) | ||
| implementation(projects.sentryAndroidTimber) | ||
| implementation(projects.sentryCompose) | ||
| implementation(projects.sentryKotlinExtensions) | ||
|
|
@@ -148,17 +169,24 @@ dependencies { | |
| implementation(libs.androidx.navigation.compose) | ||
| implementation(libs.androidx.recyclerview) | ||
| implementation(libs.androidx.browser) | ||
| implementation(libs.androidx.room3.runtime) | ||
| implementation(libs.bundles.androidx.room2) | ||
| implementation(libs.bundles.androidx.sqlite.drivers) | ||
| implementation(libs.camerax.camera2) | ||
| implementation(libs.camerax.core) | ||
| implementation(libs.camerax.lifecycle) | ||
| implementation(libs.camerax.view) | ||
| implementation(libs.coil.compose) | ||
| implementation(libs.kotlinx.coroutines.android) | ||
| implementation(libs.lottie.compose) | ||
| implementation(libs.retrofit) | ||
| implementation(libs.retrofit.gson) | ||
| implementation(libs.sentry.native.ndk) | ||
| implementation(libs.sqldelight.android.driver) | ||
| implementation(libs.timber) | ||
| implementation(libs.camerax.core) | ||
| implementation(libs.camerax.camera2) | ||
| implementation(libs.camerax.lifecycle) | ||
| implementation(libs.camerax.view) | ||
|
|
||
| ksp(libs.androidx.room.compiler) | ||
| ksp(libs.androidx.room3.compiler) | ||
|
|
||
| debugImplementation(projects.sentryAndroidDistribution) | ||
| debugImplementation(libs.leakcanary) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| package io.sentry.samples.android.sqlite | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From here on I've flagged what few items I think are of interest. Your time is probably better spent spinning up the sample app from a local branch and seeing whether you have any feedback. |
||
|
|
||
| /** | ||
| * Display text for each "SQL run" summary shown in the [SQLiteActivity] screen UI. Documentation | ||
| * only / never executed. The real statements live in [SqlStatements]. | ||
| */ | ||
| internal data class DisplayInfo(val sql: String, val sqlHeavy: String = sql) | ||
|
|
||
| internal val DRIVER_DIRECT = | ||
| DisplayInfo( | ||
| sql = | ||
| """ | ||
| CREATE TABLE IF NOT EXISTS song(…) | ||
| INSERT INTO song(title, artist) VALUES (?, ?) | ||
| SELECT count(*) FROM song | ||
| """ | ||
| .trimIndent(), | ||
| sqlHeavy = | ||
| """ | ||
| CREATE TABLE IF NOT EXISTS song(…) | ||
| INSERT INTO song(title, artist) VALUES (?, ?) | ||
| INSERT INTO song(title, artist) VALUES (?, ?), (?, ?), … (?, ?) | ||
| SELECT id, title, artist FROM song | ||
| SELECT count(*) FROM song | ||
| -- then, per row: appWork() = 500x SHA-256, in the app (not in any span) | ||
| """ | ||
| .trimIndent(), | ||
| ) | ||
|
|
||
| internal val DRIVER_ROOM2 = | ||
| DisplayInfo( | ||
| sql = | ||
| """ | ||
| INSERT OR ABORT INTO `song` (…) VALUES (nullif(?, 0), ?, ?) | ||
| SELECT count(*) FROM song | ||
| """ | ||
| .trimIndent(), | ||
| sqlHeavy = | ||
| """ | ||
| INSERT OR ABORT INTO `song` (…) VALUES (nullif(?, 0), ?, ?) | ||
| SELECT * FROM song | ||
| SELECT count(*) FROM song | ||
| -- then, per row: appWork() = 500x SHA-256, outside the step()-timed spans | ||
| """ | ||
| .trimIndent(), | ||
| ) | ||
|
|
||
| // Room 3 issues the same statements as Room 2 (see SqlStatements.driverWithRoom3). | ||
| internal val DRIVER_ROOM3 = DRIVER_ROOM2 | ||
|
|
||
| internal val OPENHELPER_DIRECT = | ||
| DisplayInfo( | ||
| sql = | ||
| """ | ||
| CREATE TABLE IF NOT EXISTS song(…) | ||
| INSERT INTO song(title, artist) VALUES (?, ?) | ||
| SELECT count(*) FROM song | ||
| """ | ||
| .trimIndent(), | ||
| sqlHeavy = | ||
| """ | ||
| CREATE TABLE IF NOT EXISTS song(…) | ||
| INSERT INTO song(title, artist) VALUES (?, ?) | ||
| INSERT INTO song(title, artist) VALUES (?, ?), (?, ?), … (?, ?) | ||
| SELECT id, title, artist FROM song | ||
| SELECT count(*) FROM song | ||
| -- then, per row: appWork() = 500x SHA-256, in the app | ||
| """ | ||
| .trimIndent(), | ||
| ) | ||
|
|
||
| internal val OPENHELPER_ROOM = | ||
| DisplayInfo( | ||
| sql = | ||
| """ | ||
| INSERT OR ABORT INTO `song` (…) VALUES (nullif(?, 0), ?, ?) | ||
| SELECT count(*) FROM song | ||
| """ | ||
| .trimIndent(), | ||
| sqlHeavy = | ||
| """ | ||
| INSERT OR ABORT INTO `song` (…) VALUES (nullif(?, 0), ?, ?) | ||
| SELECT * FROM song | ||
| SELECT count(*) FROM song | ||
| -- then, per row: appWork() = 500x SHA-256, in the app | ||
| """ | ||
| .trimIndent(), | ||
| ) | ||
|
|
||
| internal val OPENHELPER_SQLDELIGHT = | ||
| DisplayInfo( | ||
| sql = | ||
| """ | ||
| INSERT INTO song(title, artist) VALUES (?, ?) | ||
| SELECT count(*) FROM song | ||
| """ | ||
| .trimIndent(), | ||
| sqlHeavy = | ||
| """ | ||
| INSERT INTO song(title, artist) VALUES (?, ?) | ||
| SELECT * FROM song | ||
| SELECT count(*) FROM song | ||
| -- then, per row: appWork() = 500x SHA-256, in the app | ||
| """ | ||
| .trimIndent(), | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've included deps that are only relevant to the sample app b/c that matched prior art. Chime in if you want me to break with that practice and move the new sample app deps to its
build.gradlefile.