Skip to content

Commit 049f9d2

Browse files
runningcodeclaude
andauthored
Replace Emerge Distribution with Sentry Build Distribution (#623)
## Summary This PR replaces the Emerge Distribution library with Sentry's Build Distribution functionality for checking and downloading app updates in the Android app. - Remove `emergeDistribution` dependency from gradle version catalog - Remove `emerge.distribution.*` manifest placeholders from build.gradle.kts - Replace `Distribution.checkForUpdate()` API calls with `Sentry.distribution().checkForUpdateBlocking()` - Update `VersionCard` composable to use Sentry's `UpdateStatus` types (`UpToDate`, `NewRelease`, `UpdateError`, `NoNetwork`) - The Sentry Gradle plugin automatically adds the `sentry-android-distribution` dependency when the `distribution` block is configured The functionality remains the same - users can check for updates in the Settings screen, and new releases are automatically downloaded when available. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <[email protected]>
1 parent fffaac6 commit 049f9d2

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

.github/workflows/android_beta_build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
EMERGE_API_TOKEN: ${{ secrets.EMERGE_API_KEY }}
4242
REAPER_API_KEY: ${{ secrets.REAPER_API_KEY }}
4343
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
44+
SENTRY_DISTRIBUTION_AUTH_TOKEN: ${{ secrets.SENTRY_DISTRIBUTION_AUTH_TOKEN }}
4445
run: ./gradlew :app:assembleBeta
4546

4647
- name: Upload APK

android/app/build.gradle.kts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ android {
2121
versionCode = 14
2222
versionName = "1.0.3"
2323

24-
manifestPlaceholders["emerge.distribution.apiKey"] = ""
25-
manifestPlaceholders["emerge.distribution.tag"] = ""
26-
2724
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2825
vectorDrawables {
2926
useSupportLibrary = true
@@ -120,11 +117,16 @@ sentry {
120117

121118
ignoredVariants.set(listOf("debug"))
122119

120+
autoInstallation.sentryVersion = "8.24.0"
123121

124122
sizeAnalysis {
125123
enabled = providers.environmentVariable("GITHUB_ACTIONS").isPresent
126124
}
127125

126+
distribution {
127+
enabledVariants.add("beta")
128+
}
129+
128130
debug = true
129131
}
130132

@@ -175,5 +177,4 @@ dependencies {
175177
debugImplementation(libs.androidx.ui.test.manifest)
176178

177179
implementation(libs.emerge.reaper)
178-
implementation(libs.emerge.distribution)
179180
}

android/app/src/main/java/com/emergetools/hackernews/features/settings/SettingsScreen.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.emergetools.hackernews.features.settings
22

3-
import android.content.Intent
4-
import android.net.Uri
53
import androidx.compose.foundation.background
64
import androidx.compose.foundation.layout.Arrangement
75
import androidx.compose.foundation.layout.Box
@@ -31,14 +29,10 @@ import androidx.compose.runtime.remember
3129
import androidx.compose.runtime.rememberCoroutineScope
3230
import androidx.compose.runtime.setValue
3331
import androidx.compose.ui.Modifier
34-
import androidx.compose.ui.platform.LocalContext
3532
import androidx.compose.ui.res.painterResource
3633
import androidx.compose.ui.tooling.preview.Devices
3734
import androidx.compose.ui.tooling.preview.Preview
3835
import androidx.compose.ui.unit.dp
39-
import androidx.core.content.ContextCompat.startActivity
40-
import com.emergetools.distribution.Distribution
41-
import com.emergetools.distribution.UpdateStatus
4236
import com.emergetools.hackernews.R
4337
import com.emergetools.hackernews.features.settings.components.BuiltByCard
4438
import com.emergetools.hackernews.features.settings.components.LoginCard
@@ -51,7 +45,11 @@ import com.emergetools.hackernews.ui.theme.HackerNewsTheme
5145
import com.emergetools.hackernews.ui.theme.HackerOrange
5246
import com.emergetools.hackernews.ui.theme.HackerRed
5347
import com.emergetools.snapshots.annotations.EmergeAppStoreSnapshot
48+
import io.sentry.Sentry
49+
import io.sentry.UpdateStatus
50+
import kotlinx.coroutines.Dispatchers
5451
import kotlinx.coroutines.launch
52+
import kotlinx.coroutines.withContext
5553

5654
@Composable
5755
fun SettingsScreen(
@@ -91,7 +89,7 @@ fun SettingsScreen(
9189
}
9290
)
9391
Spacer(modifier = Modifier.height(8.dp))
94-
if (Distribution.isEnabled()) {
92+
if (Sentry.distribution().isEnabled) {
9593
SettingsSectionLabel("Version")
9694
VersionCard()
9795
Spacer(modifier = Modifier.height(8.dp))
@@ -190,7 +188,6 @@ fun SettingsScreen(
190188

191189
@Composable
192190
private fun VersionCard() {
193-
val context = LocalContext.current
194191
val scope = rememberCoroutineScope()
195192
var isLoading by remember { mutableStateOf(false) }
196193
var status by remember { mutableStateOf<UpdateStatus?>(null) }
@@ -214,7 +211,8 @@ private fun VersionCard() {
214211
true -> "Loading..."
215212
else -> when (status) {
216213
is UpdateStatus.UpToDate -> "Up to date!"
217-
is UpdateStatus.Error -> (status as UpdateStatus.Error).message
214+
is UpdateStatus.UpdateError -> (status as UpdateStatus.UpdateError).message
215+
is UpdateStatus.NoNetwork -> (status as UpdateStatus.NoNetwork).message
218216
is UpdateStatus.NewRelease -> "New release!"
219217
else -> "Check for updates"
220218
}
@@ -223,11 +221,12 @@ private fun VersionCard() {
223221
scope.launch {
224222
isLoading = true
225223
status = null
226-
status = Distribution.checkForUpdate(context)
224+
status = withContext(Dispatchers.IO) {
225+
Sentry.distribution().checkForUpdateBlocking()
226+
}
227227
val theStatus = status
228228
if (theStatus is UpdateStatus.NewRelease) {
229-
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(theStatus.info.downloadUrl))
230-
context.startActivity(browserIntent)
229+
Sentry.distribution().downloadUpdate(theStatus.info)
231230
}
232231
isLoading = false
233232
}

android/gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ browser = "1.9.0"
1919
emergePlugin = "4.4.0"
2020
emergeSnapshots = "1.5.0"
2121
emergeReaper = "1.0.1"
22-
emergeDistribution = "0.0.4"
2322
sentry = "6.0.0-alpha.5"
2423
shapes = "1.0.1"
2524
datastore = "1.1.7"
@@ -66,7 +65,6 @@ jsoup = { group = "org.jsoup", name = "jsoup", version.ref = "jsoup" }
6665
emerge-snapshots = { group = "com.emergetools.snapshots", name = "snapshots", version.ref = "emergeSnapshots" }
6766
emerge-snapshots-runtime = { group = "com.emergetools.snapshots", name = "snapshots-runtime", version.ref = "emergeSnapshots" }
6867
emerge-reaper = { group = "com.emergetools.reaper", name = "reaper", version.ref = "emergeReaper" }
69-
emerge-distribution = { group = "com.emergetools.distribution", name = "distribution", version.ref = "emergeDistribution" }
7068

7169
junit = { group = "junit", name = "junit", version.ref = "junit" }
7270
robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectric" }

0 commit comments

Comments
 (0)