Skip to content

Commit 8908056

Browse files
Add Sentry to MapLibreAndroidTestApp (#3716)
Co-authored-by: Bart Louwers <[email protected]> Co-authored-by: Bart Louwers <[email protected]>
1 parent 213d1c6 commit 8908056

File tree

7 files changed

+288
-76
lines changed

7 files changed

+288
-76
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: setup-android-ci
2+
description: "Sets up Android CI environment"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Free Disk Space (Ubuntu)
7+
if: startsWith(runner.name, 'GitHub Actions')
8+
uses: jlumbroso/free-disk-space@main
9+
with:
10+
tool-cache: true
11+
android: false
12+
dotnet: true
13+
haskell: true
14+
large-packages: true
15+
docker-images: true
16+
swap-storage: false
17+
18+
- name: Validate VERSION
19+
run: .github/scripts/validate-version.sh platform/android/VERSION
20+
working-directory: .
21+
shell: bash
22+
23+
- run: echo "cmake.dir=$(dirname "$(dirname "$(command -v cmake)")")" >> local.properties
24+
shell: bash
25+
26+
- uses: actions/setup-java@v4
27+
with:
28+
distribution: "temurin"
29+
java-version: "17"
30+
31+
- name: Get CMake and Ninja
32+
uses: lukka/get-cmake@latest
33+
with:
34+
cmakeVersion: 3.24.1
35+
ninjaVersion: latest
36+
37+
- uses: actions/setup-node@v4
38+
with:
39+
node-version-file: ".nvmrc"
40+
41+
- name: npm install
42+
run: npm install --ignore-scripts
43+
working-directory: .
44+
shell: bash
45+
46+
- name: run platform/android/scripts/generate-style-code.mjs
47+
run: node platform/android/scripts/generate-style-code.mjs
48+
working-directory: .
49+
shell: bash
50+
51+
- run: |
52+
python3 -m venv venv
53+
source venv/bin/activate
54+
pip3 install pre-commit
55+
shell: bash
56+
57+
- run: |
58+
source venv/bin/activate
59+
pre-commit run clang-format --all-files
60+
continue-on-error: true # this can mean files are modified, which is not an error
61+
shell: bash
62+
63+
- run: |
64+
source venv/bin/activate
65+
pre-commit run clang-format --all-files
66+
rm -rf venv
67+
shell: bash
68+
69+
- uses: infotroph/tree-is-clean@v1
70+
with:
71+
check_untracked: true
72+
73+
- uses: hendrikmuhs/[email protected]
74+
with:
75+
key: ${{ github.job }}
76+
append-timestamp: false
77+
max-size: 5G
78+
79+
- name: restore-gradle-cache
80+
uses: actions/cache@v4
81+
env:
82+
cache-name: gradle-v1
83+
with:
84+
path: ~/.gradle
85+
key: ${{ env.cache-name }}-${{ hashFiles('platform/android/buildSrc/src/main/kotlin/maplibre.dependencies.gradle.kts') }}-${{ hashFiles('platform/android/build.gradle.kts') }}-${{ hashFiles('platform/android/local.properties') }}-${{ hashFiles('platform/android/gradle/wrapper/gradle-wrapper.properties') }}
86+
restore-keys: |
87+
- ${{ env.cache-name }}

.github/workflows/android-ci.yml

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -51,86 +51,12 @@ jobs:
5151
IS_LOCAL_DEVELOPMENT: false
5252
MLN_ANDROID_STL: c++_static
5353
steps:
54-
- name: Free Disk Space (Ubuntu)
55-
if: startsWith(runner.name, 'GitHub Actions')
56-
uses: jlumbroso/free-disk-space@main
57-
with:
58-
tool-cache: true
59-
android: false
60-
dotnet: true
61-
haskell: true
62-
large-packages: true
63-
docker-images: true
64-
swap-storage: false
65-
6654
- uses: actions/checkout@v4
6755
with:
6856
submodules: recursive
6957
fetch-depth: 0
7058

71-
- name: Validate VERSION
72-
run: .github/scripts/validate-version.sh platform/android/VERSION
73-
working-directory: .
74-
75-
- run: echo "cmake.dir=$(dirname "$(dirname "$(command -v cmake)")")" >> local.properties
76-
77-
- uses: actions/setup-java@v4
78-
with:
79-
distribution: "temurin"
80-
java-version: "17"
81-
82-
- name: Get CMake and Ninja
83-
uses: lukka/get-cmake@latest
84-
with:
85-
cmakeVersion: 3.24.1
86-
ninjaVersion: latest
87-
88-
- uses: actions/setup-node@v4
89-
with:
90-
node-version-file: ".nvmrc"
91-
92-
- name: npm install
93-
run: npm install --ignore-scripts
94-
working-directory: .
95-
96-
- name: run platform/android/scripts/generate-style-code.mjs
97-
run: node platform/android/scripts/generate-style-code.mjs
98-
working-directory: .
99-
100-
- run: |
101-
python3 -m venv venv
102-
source venv/bin/activate
103-
pip3 install pre-commit
104-
105-
- run: |
106-
source venv/bin/activate
107-
pre-commit run clang-format --all-files
108-
continue-on-error: true # this can mean files are modified, which is not an error
109-
110-
- run: |
111-
source venv/bin/activate
112-
pre-commit run clang-format --all-files
113-
rm -rf venv
114-
115-
- uses: infotroph/tree-is-clean@v1
116-
with:
117-
check_untracked: true
118-
119-
- uses: hendrikmuhs/[email protected]
120-
with:
121-
key: ${{ github.job }}
122-
append-timestamp: false
123-
max-size: 5G
124-
125-
- name: restore-gradle-cache
126-
uses: actions/cache@v4
127-
env:
128-
cache-name: gradle-v1
129-
with:
130-
path: ~/.gradle
131-
key: ${{ env.cache-name }}-${{ hashFiles('platform/android/buildSrc/src/main/kotlin/maplibre.dependencies.gradle.kts') }}-${{ hashFiles('platform/android/build.gradle.kts') }}-${{ hashFiles('platform/android/local.properties') }}-${{ hashFiles('platform/android/gradle/wrapper/gradle-wrapper.properties') }}
132-
restore-keys: |
133-
- ${{ env.cache-name }}
59+
- uses: ./.github/actions/setup-android-ci
13460

13561
- name: Check code style
13662
if: matrix.renderer == 'opengl'
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: android-testapp-release
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
workflow_dispatch:
8+
9+
jobs:
10+
create-android-testapp-release:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Create Release
14+
run: |
15+
gh release create android-testapp-${{ github.sha }} \
16+
--draft=false \
17+
--prerelease=false \
18+
--latest=false \
19+
--title android-testapp-${{ github.sha }}
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
23+
android-build-testapp:
24+
needs: [create-android-testapp-release]
25+
runs-on: ubuntu-24.04
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
renderer: [opengl, vulkan]
30+
defaults:
31+
run:
32+
working-directory: platform/android
33+
env:
34+
BUILDTYPE: Debug
35+
IS_LOCAL_DEVELOPMENT: false
36+
MLN_ANDROID_STL: c++_static
37+
SENTRY_ORG: maplibre
38+
SENTRY_PROJECT: maplibre-android
39+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
40+
SENTRY_DSN: ${{ secrets.SENTRY_DSN_ANDROID }}
41+
steps:
42+
- uses: actions/checkout@v4
43+
with:
44+
submodules: recursive
45+
fetch-depth: 0
46+
47+
- uses: ./.github/actions/setup-android-ci
48+
49+
- run: ./gradlew assemble${{ matrix.renderer }}Release
50+
51+
- name: Install sentry-cli
52+
run: curl -sL https://sentry.io/get-cli/ | sh
53+
54+
- name: Upload debug symbols to sentry
55+
run: sentry-cli debug-files upload MapLibreAndroidTestApp
56+
57+
- name: Upload Linux artifact
58+
run: |
59+
gh release upload android-testapp-${{ github.sha }} MapLibreAndroidTestApp/build/outputs/apk/${{ matrix.renderer }}/release/MapLibreAndroidTestApp-${{ matrix.renderer }}-release.apk
60+
env:
61+
GH_TOKEN: ${{ github.token }}

platform/android/MapLibreAndroidTestApp/build.gradle.kts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ plugins {
99
id("maplibre.gradle-lint")
1010
}
1111

12-
1312
fun obtainTestBuildType(): String {
1413
return if (project.hasProperty("testBuildType")) {
1514
project.properties["testBuildType"] as String
@@ -31,6 +30,7 @@ android {
3130
versionName = "6.0.1"
3231
testInstrumentationRunner = "org.maplibre.android.InstrumentationRunner"
3332
multiDexEnabled = true
33+
manifestPlaceholders["SENTRY_DSN"] = ""
3434
}
3535

3636
nativeBuild(listOf("example-custom-layer"))
@@ -47,13 +47,24 @@ android {
4747
isMinifyEnabled = false
4848
isShrinkResources = false
4949
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
50+
51+
packaging {
52+
jniLibs {
53+
keepDebugSymbols += "**/*.so"
54+
}
55+
}
56+
buildConfigField("String", "SENTRY_DSN", "\"" + (System.getenv("SENTRY_DSN") ?: "") + "\"")
57+
manifestPlaceholders["SENTRY_DSN"] = System.getenv("SENTRY_DSN") ?: ""
5058
}
5159
getByName("release") {
5260
isMinifyEnabled = true
5361
isShrinkResources = true
5462
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
5563
testProguardFiles("test-proguard-rules.pro")
5664
signingConfig = signingConfigs.getByName("debug")
65+
66+
buildConfigField("String", "SENTRY_DSN", "\"" + (System.getenv("SENTRY_DSN") ?: "") + "\"")
67+
manifestPlaceholders["SENTRY_DSN"] = System.getenv("SENTRY_DSN") ?: ""
5768
}
5869
}
5970

@@ -119,3 +130,5 @@ dependencies {
119130
androidTestImplementation(libs.androidxTestCoreKtx)
120131
androidTestImplementation(libs.kotlinxCoroutinesTest)
121132
}
133+
134+
apply<SentryConditionalPlugin>()

platform/android/MapLibreAndroidTestApp/src/main/AndroidManifest.xml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,68 @@
12831283
android:name="android.support.PARENT_ACTIVITY"
12841284
android:value=".activity.FeatureOverviewActivity" />
12851285
</activity>
1286+
1287+
<!-- Sentry setup -->
1288+
<!-- Required: set your sentry.io project identifier (DSN) -->
1289+
<meta-data
1290+
android:name="io.sentry.dsn"
1291+
android:value="${SENTRY_DSN}"
1292+
/>
1293+
1294+
<!-- Add data like request headers, user ip address and device name, see https://docs.sentry.io/platforms/android/data-management/data-collected/ for more info -->
1295+
<meta-data
1296+
android:name="io.sentry.send-default-pii"
1297+
android:value="true"
1298+
/>
1299+
1300+
<!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->
1301+
<meta-data
1302+
android:name="io.sentry.traces.user-interaction.enable"
1303+
android:value="true"
1304+
/>
1305+
<!-- enable screenshot for crashes -->
1306+
<meta-data
1307+
android:name="io.sentry.attach-screenshot"
1308+
android:value="true"
1309+
/>
1310+
<!-- enable view hierarchy for crashes -->
1311+
<meta-data
1312+
android:name="io.sentry.attach-view-hierarchy"
1313+
android:value="true"
1314+
/>
1315+
1316+
<!-- enable the performance API by setting a sample-rate, adjust in production env -->
1317+
<meta-data
1318+
android:name="io.sentry.traces.sample-rate"
1319+
android:value="1.0"
1320+
/>
1321+
1322+
<!-- Enable UI profiling, adjust in production env. This is evaluated only once per session -->
1323+
<meta-data
1324+
android:name="io.sentry.traces.profiling.session-sample-rate"
1325+
android:value="1.0"
1326+
/>
1327+
<!-- Set profiling mode. For more info see https://docs.sentry.io/platforms/android/profiling/#enabling-ui-profiling -->
1328+
<meta-data
1329+
android:name="io.sentry.traces.profiling.lifecycle"
1330+
android:value="trace"
1331+
/>
1332+
<!-- Enable profiling on app start. The app start profile will be stopped automatically when the app start root span finishes -->
1333+
<meta-data
1334+
android:name="io.sentry.traces.profiling.start-on-app-start"
1335+
android:value="true"
1336+
/>
1337+
1338+
<!-- record session replays for 100% of errors and 10% of sessions -->
1339+
<meta-data
1340+
android:name="io.sentry.session-replay.on-error-sample-rate"
1341+
android:value="1.0"
1342+
/>
1343+
<meta-data
1344+
android:name="io.sentry.session-replay.session-sample-rate"
1345+
android:value="0.1"
1346+
/>
1347+
12861348
</application>
12871349

12881350
</manifest>

platform/android/buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ dependencies {
1414
implementation("com.android.tools.build:gradle:8.6.0")
1515
implementation("com.android.application:com.android.application.gradle.plugin:8.6.0")
1616
implementation("commons-collections:commons-collections:3.2.2")
17+
implementation("io.sentry:sentry-android-gradle-plugin:5.9.0")
1718
}

0 commit comments

Comments
 (0)