Skip to content

Commit 8ff7db3

Browse files
committed
Merge branch 'main' into feedback-ui
# Conflicts: # CHANGELOG.md
2 parents 53e13fc + 3f05680 commit 8ff7db3

File tree

11 files changed

+379
-18
lines changed

11 files changed

+379
-18
lines changed

.github/workflows/codeql-analysis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444

4545
# Initializes the CodeQL tools for scanning.
4646
- name: Initialize CodeQL
47-
uses: github/codeql-action/init@dd746615b3b9d728a6a37ca2045b68ca76d4841a # [email protected].8
47+
uses: github/codeql-action/init@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # [email protected].9
4848
with:
4949
languages: ${{ matrix.language }}
5050
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -55,7 +55,7 @@ jobs:
5555
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5656
# If this step fails, then you should remove it and run the build manually (see below)
5757
- name: Autobuild
58-
uses: github/codeql-action/autobuild@dd746615b3b9d728a6a37ca2045b68ca76d4841a # [email protected].8
58+
uses: github/codeql-action/autobuild@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # [email protected].9
5959

6060
# ℹ️ Command-line programs to run using the OS shell.
6161
# 📚 https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
@@ -66,4 +66,4 @@ jobs:
6666
# make bootstrap
6767
# make release
6868
- name: Perform CodeQL Analysis
69-
uses: github/codeql-action/analyze@dd746615b3b9d728a6a37ca2045b68ca76d4841a # [email protected].8
69+
uses: github/codeql-action/analyze@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # [email protected].9

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
steps:
2020
- name: Get auth token
2121
id: token
22-
uses: actions/create-github-app-token@136412a57a7081aa63c935a2cc2918f76c34f514 # v1.11.2
22+
uses: actions/create-github-app-token@0d564482f06ca65fa9e77e2510873638c82206f2 # v1.11.5
2323
with:
2424
app-id: ${{ vars.SENTRY_RELEASE_BOT_CLIENT_ID }}
2525
private-key: ${{ secrets.SENTRY_RELEASE_BOT_PRIVATE_KEY }}

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@
2020
<FeedbackWidget/>
2121
```
2222

23+
- Adds Sentry Android Gradle Plugin as an experimental Expo plugin feature ([#4440](https://github.com/getsentry/sentry-react-native/pull/4440))
24+
25+
To enable the plugin add the `enableAndroidGradlePlugin` in the `@sentry/react-native/expo` of the Expo application configuration.
26+
27+
```js
28+
"plugins": [
29+
[
30+
"@sentry/react-native/expo",
31+
{
32+
"experimental_android": {
33+
"enableAndroidGradlePlugin": true,
34+
}
35+
}
36+
],
37+
```
38+
39+
To learn more about the available configuration options visit [the documentation](https://docs.sentry.io/platforms/react-native/manual-setup/expo/expo-sagp/).
40+
2341
### Fixes
2442

2543
- Various crashes and issues of Session Replay on Android. See the Android SDK version bump for more details. ([#4529](https://github.com/getsentry/sentry-react-native/pull/4529))

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"@sentry-internal/eslint-config-sdk": "8.54.0",
8282
"@sentry-internal/eslint-plugin-sdk": "8.54.0",
8383
"@sentry-internal/typescript": "8.54.0",
84-
"@sentry/wizard": "3.40.0",
84+
"@sentry/wizard": "3.42.0",
8585
"@testing-library/react-native": "^12.7.2",
8686
"@types/jest": "^29.5.13",
8787
"@types/node": "^20.9.3",

packages/core/plugin/src/withSentry.ts

+11
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import { createRunOncePlugin } from 'expo/config-plugins';
33

44
import { bold, sdkPackage, warnOnce } from './utils';
55
import { withSentryAndroid } from './withSentryAndroid';
6+
import type { SentryAndroidGradlePluginOptions } from './withSentryAndroidGradlePlugin';
7+
import { withSentryAndroidGradlePlugin } from './withSentryAndroidGradlePlugin';
68
import { withSentryIOS } from './withSentryIOS';
79

810
interface PluginProps {
911
organization?: string;
1012
project?: string;
1113
authToken?: string;
1214
url?: string;
15+
experimental_android?: SentryAndroidGradlePluginOptions;
1316
}
1417

1518
const withSentryPlugin: ConfigPlugin<PluginProps | void> = (config, props) => {
@@ -27,6 +30,14 @@ const withSentryPlugin: ConfigPlugin<PluginProps | void> = (config, props) => {
2730
} catch (e) {
2831
warnOnce(`There was a problem with configuring your native Android project: ${e}`);
2932
}
33+
// if `enableAndroidGradlePlugin` is provided configure the Sentry Android Gradle Plugin
34+
if (props?.experimental_android && props?.experimental_android?.enableAndroidGradlePlugin) {
35+
try {
36+
cfg = withSentryAndroidGradlePlugin(cfg, props.experimental_android);
37+
} catch (e) {
38+
warnOnce(`There was a problem with configuring Sentry Android Gradle Plugin: ${e}`);
39+
}
40+
}
3041
try {
3142
cfg = withSentryIOS(cfg, sentryProperties);
3243
} catch (e) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import { withAppBuildGradle, withProjectBuildGradle } from '@expo/config-plugins';
2+
3+
import { warnOnce } from './utils';
4+
5+
export interface SentryAndroidGradlePluginOptions {
6+
enableAndroidGradlePlugin?: boolean;
7+
includeProguardMapping?: boolean;
8+
dexguardEnabled?: boolean;
9+
autoUploadNativeSymbols?: boolean;
10+
autoUploadProguardMapping?: boolean;
11+
uploadNativeSymbols?: boolean;
12+
includeNativeSources?: boolean;
13+
includeSourceContext?: boolean;
14+
}
15+
16+
/**
17+
* Adds the Sentry Android Gradle Plugin to the project.
18+
* https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/#enable-sentry-agp
19+
*/
20+
export function withSentryAndroidGradlePlugin(
21+
config: any,
22+
{
23+
includeProguardMapping = true,
24+
dexguardEnabled = false,
25+
autoUploadProguardMapping = true,
26+
uploadNativeSymbols = true,
27+
autoUploadNativeSymbols = true,
28+
includeNativeSources = true,
29+
includeSourceContext = false,
30+
}: SentryAndroidGradlePluginOptions = {},
31+
): any {
32+
const version = '4.14.1';
33+
34+
// Modify android/build.gradle
35+
const withSentryProjectBuildGradle = (config: any): any => {
36+
return withProjectBuildGradle(config, (projectBuildGradle: any) => {
37+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
38+
if (!projectBuildGradle.modResults || !projectBuildGradle.modResults.contents) {
39+
warnOnce('android/build.gradle content is missing or undefined.');
40+
return config;
41+
}
42+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
43+
if (projectBuildGradle.modResults.language !== 'groovy') {
44+
warnOnce('Cannot configure Sentry in android/build.gradle because it is not in Groovy.');
45+
return config;
46+
}
47+
48+
const dependency = `classpath("io.sentry:sentry-android-gradle-plugin:${version}")`;
49+
50+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
51+
if (projectBuildGradle.modResults.contents.includes(dependency)) {
52+
warnOnce('sentry-android-gradle-plugin dependency in already in android/build.gradle.');
53+
return config;
54+
}
55+
56+
try {
57+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
58+
const updatedContents = projectBuildGradle.modResults.contents.replace(
59+
/dependencies\s*{/,
60+
`dependencies {\n ${dependency}`,
61+
);
62+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
63+
if (updatedContents === projectBuildGradle.modResults.contents) {
64+
warnOnce('Failed to inject the dependency. Could not find `dependencies` in build.gradle.');
65+
} else {
66+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
67+
projectBuildGradle.modResults.contents = updatedContents;
68+
}
69+
} catch (error) {
70+
warnOnce(`An error occurred while trying to modify build.gradle`);
71+
}
72+
return projectBuildGradle;
73+
});
74+
};
75+
76+
// Modify android/app/build.gradle
77+
const withSentryAppBuildGradle = (config: any): any => {
78+
return withAppBuildGradle(config, (config: any) => {
79+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
80+
if (config.modResults.language !== 'groovy') {
81+
warnOnce('Cannot configure Sentry in android/app/build.gradle because it is not in Groovy.');
82+
return config;
83+
}
84+
const sentryPlugin = `apply plugin: "io.sentry.android.gradle"`;
85+
const sentryConfig = `
86+
sentry {
87+
autoUploadProguardMapping = ${autoUploadProguardMapping}
88+
includeProguardMapping = ${includeProguardMapping}
89+
dexguardEnabled = ${dexguardEnabled}
90+
uploadNativeSymbols = ${uploadNativeSymbols}
91+
autoUploadNativeSymbols = ${autoUploadNativeSymbols}
92+
includeNativeSources = ${includeNativeSources}
93+
includeSourceContext = ${includeSourceContext}
94+
tracingInstrumentation {
95+
enabled = false
96+
}
97+
autoInstallation {
98+
enabled = false
99+
}
100+
}`;
101+
102+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
103+
let contents = config.modResults.contents;
104+
105+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
106+
if (!contents.includes(sentryPlugin)) {
107+
contents = `${sentryPlugin}\n${contents}`;
108+
}
109+
110+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
111+
if (!contents.includes('sentry {')) {
112+
contents = `${contents}\n${sentryConfig}`;
113+
}
114+
115+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
116+
config.modResults.contents = contents;
117+
return config;
118+
});
119+
};
120+
121+
return withSentryAppBuildGradle(withSentryProjectBuildGradle(config));
122+
}

0 commit comments

Comments
 (0)