Skip to content

Commit 206193c

Browse files
committed
Run Android demo
1 parent 8e0833e commit 206193c

File tree

2 files changed

+133
-3
lines changed

2 files changed

+133
-3
lines changed

.github/workflows/run-demo.yml

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run Windows Build
1+
name: Run Demo Builds
22

33
on:
44
workflow_call:
@@ -53,4 +53,109 @@ jobs:
5353
} else {
5454
Write-Error "No SentaurSurvivors executable found in build artifacts"
5555
exit 1
56-
}
56+
}
57+
58+
test-android:
59+
name: Test Android Build
60+
runs-on: ubuntu-latest
61+
62+
steps:
63+
- name: Download Android Build
64+
uses: actions/download-artifact@v4
65+
with:
66+
name: Build-Android
67+
path: ./build
68+
github-token: ${{ secrets.GITHUB_TOKEN }}
69+
run-id: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.id || github.run_id }}
70+
71+
- name: Set up JDK 17
72+
uses: actions/setup-java@v4
73+
with:
74+
java-version: '17'
75+
distribution: 'temurin'
76+
77+
- name: Enable KVM group perms
78+
run: |
79+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
80+
sudo udevadm control --reload-rules
81+
sudo udevadm trigger --name-match=kvm
82+
83+
- name: Set up Android SDK
84+
uses: android-actions/setup-android@v3
85+
86+
- name: AVD cache
87+
uses: actions/cache@v4
88+
id: avd-cache
89+
with:
90+
path: |
91+
~/.android/avd/*
92+
~/.android/adb*
93+
key: avd-29
94+
95+
- name: Create AVD and generate snapshot for caching
96+
if: steps.avd-cache.outputs.cache-hit != 'true'
97+
uses: reactivecircus/android-emulator-runner@v2
98+
with:
99+
api-level: 29
100+
target: google_apis
101+
arch: x86_64
102+
profile: Nexus 6
103+
force-avd-creation: false
104+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
105+
disable-animations: false
106+
script: echo "Generated AVD snapshot for caching."
107+
108+
- name: Find APK file
109+
id: find-apk
110+
run: |
111+
APK_FILE=$(find ./build -name "*.apk" -type f | head -1)
112+
if [ -z "$APK_FILE" ]; then
113+
echo "Error: No APK file found in build artifacts"
114+
exit 1
115+
fi
116+
echo "Found APK: $APK_FILE"
117+
echo "apk_path=$APK_FILE" >> $GITHUB_OUTPUT
118+
119+
- name: Run Android Emulator
120+
uses: reactivecircus/android-emulator-runner@v2
121+
env:
122+
SENTRY_DSN: ${{ secrets.DSN }}
123+
with:
124+
api-level: 29
125+
target: google_apis
126+
arch: x86_64
127+
profile: Nexus 6
128+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
129+
disable-animations: true
130+
script: |
131+
echo "Installing APK..."
132+
adb install "${{ steps.find-apk.outputs.apk_path }}"
133+
134+
echo "Starting app..."
135+
# Get package name from APK
136+
PACKAGE_NAME=$(aapt dump badging "${{ steps.find-apk.outputs.apk_path }}" | grep package | awk '{print $2}' | sed "s/name='//" | sed "s/'.*//")
137+
echo "Package name: $PACKAGE_NAME"
138+
139+
# Get main activity
140+
MAIN_ACTIVITY=$(aapt dump badging "${{ steps.find-apk.outputs.apk_path }}" | grep "launchable-activity" | awk '{print $2}' | sed "s/name='//" | sed "s/'.*//")
141+
echo "Main activity: $MAIN_ACTIVITY"
142+
143+
# Pass DSN as Intent extra for Android runtime configuration
144+
adb shell am start -n $PACKAGE_NAME/$MAIN_ACTIVITY --es dsn "$SENTRY_DSN"
145+
146+
echo "App started, waiting for execution..."
147+
sleep 5
148+
149+
# Check if app is running
150+
adb shell "ps | grep $PACKAGE_NAME" || echo "App might not be running"
151+
152+
echo "Waiting for app to initialize..."
153+
sleep 25
154+
155+
echo "Capturing logs..."
156+
adb logcat -d | grep -i "unity\|sentry\|sentaur\|dsn\|configure" || echo "No relevant logs found"
157+
158+
echo "Stopping app..."
159+
adb shell am force-stop $PACKAGE_NAME
160+
161+
echo "Android demo completed successfully"

Assets/Scripts/Config/SentryOptionConfiguration.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,31 @@ public override void Configure(SentryUnityOptions options)
2323
return;
2424
}
2525

26+
// On Android, try to get DSN from Intent extras
27+
#if UNITY_ANDROID && !UNITY_EDITOR
28+
Debug.Log("Getting the 'DSN' from Android Intent extras.");
29+
30+
try
31+
{
32+
using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
33+
using (AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
34+
using (AndroidJavaObject intent = currentActivity.Call<AndroidJavaObject>("getIntent"))
35+
{
36+
dsn = intent.Call<string>("getStringExtra", "dsn");
37+
if (!string.IsNullOrEmpty(dsn))
38+
{
39+
Debug.Log("Setting the 'DSN' from Android Intent extras.");
40+
options.Dsn = dsn;
41+
return;
42+
}
43+
}
44+
}
45+
catch (System.Exception e)
46+
{
47+
Debug.LogWarning($"Failed to get DSN from Android Intent: {e.Message}");
48+
}
49+
#endif
50+
2651
Debug.Log("Getting the 'DSN' from the commandline arguments.");
2752

2853
dsn = ArgumentReader.GetCommandLineArg("dsn");
@@ -33,7 +58,7 @@ public override void Configure(SentryUnityOptions options)
3358
}
3459
else
3560
{
36-
Debug.LogError("Failed to get the 'DSN' from both environment variable and command line arguments.");
61+
Debug.LogError("Failed to get the 'DSN' from environment variable, Intent extras, and command line arguments.");
3762
}
3863
}
3964
}

0 commit comments

Comments
 (0)