Skip to content

Commit 5c16cdc

Browse files
authored
fix(replay): Allow excluding the sentry-android-replay module from android targets (#5174)
* fix(replay): Allow excluding the sentry-android-replay module from android builds * Changelog * Address PR review
1 parent 8a4ce6f commit 5c16cdc

File tree

15 files changed

+467
-2
lines changed

15 files changed

+467
-2
lines changed

.github/workflows/update-deps.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ jobs:
1919
secrets:
2020
api-token: ${{ secrets.CI_DEPLOY_KEY }}
2121

22+
android-stubs:
23+
uses: getsentry/github-workflows/.github/workflows/updater.yml@v2
24+
with:
25+
path: scripts/update-android-stubs.sh
26+
name: Android SDK Stubs
27+
pr-strategy: update
28+
secrets:
29+
api-token: ${{ secrets.CI_DEPLOY_KEY }}
30+
2231
cocoa:
2332
uses: getsentry/github-workflows/.github/workflows/updater.yml@v2
2433
with:

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88
99
## Unreleased
1010

11+
### Fixes
12+
13+
- Session Replay: Allow excluding `sentry-android-replay` from android targets ([#5174](https://github.com/getsentry/sentry-react-native/pull/5174))
14+
- If you are not interested in using Session Replay, you can exclude the `sentry-android-replay` module from your Android targets as follows (saves nearly 40KB compressed and 80KB uncompressed off the bundle size):
15+
16+
```gradle
17+
// from the android's root build.gradle file
18+
subprojects {
19+
configurations.all {
20+
exclude group: 'io.sentry', module: 'sentry-android-replay'
21+
}
22+
}
23+
```
24+
1125
### Dependencies
1226

1327
- Bump JavaScript SDK from v10.8.0 to v10.11.0 ([#5142](https://github.com/getsentry/sentry-react-native/pull/5142), [#5145](https://github.com/getsentry/sentry-react-native/pull/5145), [#5157](https://github.com/getsentry/sentry-react-native/pull/5157))

packages/core/android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ android {
5353
}
5454

5555
dependencies {
56+
compileOnly files('libs/replay-stubs.jar')
5657
implementation 'com.facebook.react:react-native:+'
5758
api 'io.sentry:sentry-android:8.21.1'
5859
}
1.17 KB
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This module is needed to successfully compile the Android target for the cases when `sentry-android-replay` is excluded from the host app classpath (for example, to reduce the resulting bundle/apk size), e.g. via the following snippet:
2+
3+
```gradle
4+
subprojects {
5+
configurations.all {
6+
exclude group: 'io.sentry', module: 'sentry-android-replay'
7+
}
8+
}
9+
```
10+
11+
It provides stubs for the Replay classes that are used by the React Native SDK and is being added as a `compileOnly` dependency to `android/build.gradle` (meaning, it is not present at runtime and does not affect our customers' code).
12+
13+
In addition, we also check for the `sentry-android-replay` classes presence at runtime and only then instantiate the replay-related classes (currently only `RNSentryReplayBreadcrumbConverter`) to not cause a `NoClassDefFoundError`.
14+
15+
## Updating the stubs
16+
17+
To update the stubs, just run `yarn build` from the root of the repo and it will recompile the classes and put them under `packages/core/android/libs/replay-stubs.jar`. Check this newly generated `.jar` in and push.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
allprojects {
2+
repositories {
3+
mavenCentral()
4+
}
5+
}
6+
7+
apply plugin: 'java-library'
8+
9+
java {
10+
sourceCompatibility = JavaVersion.VERSION_1_8
11+
targetCompatibility = JavaVersion.VERSION_1_8
12+
}
13+
14+
tasks.named('jar', Jar) {
15+
archiveBaseName.set('replay-stubs')
16+
archiveVersion.set('')
17+
destinationDirectory.set(file("$rootDir/../libs"))
18+
}
19+
20+
dependencies {
21+
compileOnly 'io.sentry:sentry:8.21.1'
22+
}
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

packages/core/android/replay-stubs/gradlew

Lines changed: 251 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)