Skip to content

Commit 48a8a38

Browse files
committed
Merge branch 'main' into deps/modules/sentry-cocoa.properties/8.43.0
2 parents 5dc5240 + f691dd3 commit 48a8a38

File tree

17 files changed

+155
-65
lines changed

17 files changed

+155
-65
lines changed

.github/workflows/android-smoke-test.yml

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,43 +42,34 @@ jobs:
4242
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
4343
sudo udevadm control --reload-rules
4444
sudo udevadm trigger --name-match=kvm
45-
46-
# outputs variables: api-level, label, target
47-
- name: Configure Android Settings
48-
id: config
45+
46+
# Make sure that the required directories and .cfg do exists. Workaround to keep ADV happy on `ubuntu-latest`.
47+
- name: Setup Android directories
4948
run: |
50-
# Setup API Level
51-
$apiLevel = '${{ inputs.api-level }}'
52-
if ( $apiLevel -eq 'latest')
53-
{
54-
# Gets the latest API level that isn't in Beta/Alpha
55-
$response = (Invoke-WebRequest -UseBasicParsing -Uri "https://developer.android.com/studio/releases/platforms").Content
56-
$result = [regex]::Match($response, " \(API level (?<model>\d+)\)")
57-
$apiLevel = $result.Groups["model"].Value
58-
Write-Output "Latest API is $apiLevel"
59-
$label = "$apiLevel (latest)"
60-
}
61-
else
62-
{
63-
Write-Output "Current API is $apiLevel"
64-
}
65-
# Setup Arch and Target
66-
$target = $apiLevel -ge 30 ? 'google_apis' : 'default'
67-
Write-Output "Current Target is $target"
68-
"target=$target" >> $env:GITHUB_OUTPUT
69-
"api-level=$apiLevel" >> $env:GITHUB_OUTPUT
70-
"label=$($label ?? $apiLevel)" >> $env:GITHUB_OUTPUT
71-
49+
mkdir -p $HOME/.android
50+
mkdir -p $HOME/.android/avd
51+
touch $HOME/.android/repositories.cfg
52+
7253
- name: Run Android Smoke Tests
7354
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b # [email protected]
7455
id: smoke-test
7556
timeout-minutes: 30
7657
with:
77-
api-level: ${{ steps.config.outputs.api-level }}
78-
target: ${{ steps.config.outputs.target }}
79-
force-avd-creation: false
80-
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
58+
api-level: ${{ inputs.api-level }}
59+
target: 'google_apis'
60+
channel: 'stable'
61+
force-avd-creation: true
8162
disable-animations: true
63+
disable-spellchecker: true
64+
emulator-options: >
65+
-no-window
66+
-no-snapshot-save
67+
-gpu swiftshader_indirect
68+
-noaudio
69+
-no-boot-anim
70+
-camera-back none
71+
-camera-front none
72+
-timezone US/Pacific
8273
arch: x86_64
8374
script: |
8475
adb wait-for-device
@@ -90,6 +81,6 @@ jobs:
9081
if: ${{ failure() }}
9182
uses: actions/upload-artifact@v4
9283
with:
93-
name: testapp-android-logs-${{ inputs.api-level }}-${{ inputs.unity-version }}-${{ inputs.try }}
84+
name: testapp-android-logs-${{ inputs.api-level }}-${{ inputs.unity-version }}
9485
path: ${{ env.ARTIFACTS_PATH }}
9586
retention-days: 14

.github/workflows/ci.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,14 @@ jobs:
445445
strategy:
446446
fail-fast: false
447447
matrix:
448-
api-level: [27, 31, 34] # last updated December 2024
448+
api-level: [30, 31, 34] # last updated January 2025
449449
unity-version: ["2019", "2022", "6000"]
450450

451451
mobile-smoke-test-compile:
452452
if: ${{ !startsWith(github.ref, 'refs/heads/release/') }}
453453
needs: [smoke-test-build]
454454
name: ${{ matrix.unity-version }} ${{ matrix.platform }} Compile Smoke Test
455-
runs-on: ${{ matrix.platform == 'iOS' && 'macos' || 'ubuntu' }}-latest
455+
runs-on: ${{ matrix.platform == 'iOS' && 'macos-latest' || 'ubuntu-latest-4-cores' }}
456456
strategy:
457457
fail-fast: false
458458
matrix:
@@ -463,7 +463,7 @@ jobs:
463463
- unity-version: "2019"
464464
ndk: "r19"
465465
- unity-version: "2022"
466-
ndk: "r21d"
466+
ndk: "r23b"
467467
- unity-version: "6000"
468468
ndk: "r23b"
469469

@@ -491,6 +491,10 @@ jobs:
491491
ndk-version: ${{ matrix.ndk }}
492492
add-to-path: false
493493

494+
- name: Setup Java for Unity
495+
if: ${{ matrix.platform == 'Android' }}
496+
run: ./scripts/ci-setup-java.ps1 -UnityVersion "${{ matrix.unity-version }}"
497+
494498
# We modify the exported gradle project to deal with the different build-environment
495499
# I.e. we're fixing the paths for SDK & NDK that have been hardcoded to point at the Unity installation
496500
- name: Modify gradle project
@@ -500,25 +504,20 @@ jobs:
500504
-AndroidSdkRoot $env:ANDROID_SDK_ROOT `
501505
-NdkPath ${{ steps.setup-ndk.outputs.ndk-path }} `
502506
-UnityVersion ${{ matrix.unity-version }}
503-
504-
- name: Setup JDK 17 for Unity 6
505-
if: ${{ matrix.platform == 'Android' && matrix.unity-version == '6000' }}
506-
uses: actions/setup-java@v3
507-
with:
508-
java-version: '17'
509-
distribution: 'temurin'
510507
511508
- name: Android smoke test
512509
if: ${{ matrix.platform == 'Android' }}
513510
run: ./scripts/smoke-test-android.ps1 Build -IsIntegrationTest -UnityVersion "${{ matrix.unity-version }}"
511+
timeout-minutes: 10
514512
env:
515513
JAVA_HOME: ${{ env.JAVA_HOME }}
516514

517515
- name: iOS smoke test
518516
if: ${{ matrix.platform == 'iOS' }}
519517
run: ./scripts/smoke-test-ios.ps1 Build -IsIntegrationTest -UnityVersion "${{ matrix.unity-version }}"
518+
timeout-minutes: 10
520519

521-
- name: Upload Project project on failure
520+
- name: Upload integration-test project on failure
522521
if: ${{ failure() }}
523522
uses: actions/upload-artifact@v4
524523
with:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
### Fixes
6+
7+
- Fixed iOS native SDK initialization that could cause memory management issues ([#1964](https://github.com/getsentry/sentry-unity/pull/1964))
8+
- The SDK now properly sets up logging by respecting the debug settings set during the configure callback. Logs created during the configuration of the native SDKs no longer get lost ([#1959]https://github.com/getsentry/sentry-unity/pull/1959)
9+
- ANR events now include the relevant mechanism they have been captured from ([#1955](https://github.com/getsentry/sentry-unity/pull/1955))
10+
511
### Dependencies
612

713
- Bump Cocoa SDK from v8.42.0 to v8.43.0 ([#1949](https://github.com/getsentry/sentry-unity/pull/1949))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Unity: keep names on select sentry-java classes & their methods - we use string-based JNI lookup in our integration.
22
-keep class io.sentry.Sentry { *; }
3+
-keep class io.sentry.Sentry$OptionsConfiguration { *; }
4+
-keep class io.sentry.android.core.SentryAndroid { *; }
35
-keep class io.sentry.SentryLevel { *; }
46
-keep class io.sentry.SentryOptions { *; }
57
-keep class io.sentry.Hub { *; }
68
-keep class io.sentry.Breadcrumb { *; }
79
-keep class io.sentry.Scope { *; }
810
-keep class io.sentry.ScopeCallback { *; }
911
-keep class io.sentry.protocol.** { *; }
12+
-dontwarn io.sentry.**

package-dev/Plugins/iOS/SentryNativeBridge.m

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import <Sentry/PrivateSentrySDKOnly.h>
2+
#import <Sentry/SentryOptions+HybridSDKs.h>
23
#import <Sentry/Sentry.h>
34

45
NS_ASSUME_NONNULL_BEGIN
@@ -30,14 +31,19 @@ void SentryNativeBridgeOptionsSetInt(const void *options, const char *name, int3
3031
dictOptions[[NSString stringWithUTF8String:name]] = [NSNumber numberWithInt:value];
3132
}
3233

33-
void SentryNativeBridgeStartWithOptions(const void *options)
34+
int SentryNativeBridgeStartWithOptions(const void *options)
3435
{
3536
NSMutableDictionary *dictOptions = (__bridge_transfer NSMutableDictionary *)options;
36-
id sentryOptions = [[SentryOptions alloc]
37-
performSelector:@selector(initWithDict:didFailWithError:)
38-
withObject:dictOptions withObject:nil];
37+
NSError *error = nil;
3938

40-
[SentrySDK performSelector:@selector(startWithOptions:) withObject:sentryOptions];
39+
SentryOptions *sentryOptions = [[SentryOptions alloc] initWithDict:dictOptions didFailWithError:&error];
40+
if (error != nil)
41+
{
42+
return 0;
43+
}
44+
45+
[SentrySDK startWithOptions:sentryOptions];
46+
return 1;
4147
}
4248

4349
int SentryNativeBridgeCrashedLastRun() { return [SentrySDK crashedLastRun] ? 1 : 0; }

package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
void *_Nullable SentryNativeBridgeOptionsNew() { return nil; }
66
void SentryNativeBridgeOptionsSetString(void *options, const char *name, const char *value) { }
77
void SentryNativeBridgeOptionsSetInt(void *options, const char *name, int32_t value) { }
8-
void SentryNativeBridgeStartWithOptions(void *options) { }
8+
int SentryNativeBridgeStartWithOptions(void *options) { return 0; }
99

1010
int SentryNativeBridgeCrashedLastRun() { return 0; }
1111

scripts/ci-env.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ switch ($name) {
1414
return "2021.3.45f1"
1515
}
1616
"unity2022" {
17-
return "2022.3.42f1"
17+
return "2022.3.55f1"
1818
}
1919
"unity2023" {
2020
return "2023.2.20f1"
2121
}
2222
"unity6000" {
23-
return "6000.0.32f1"
23+
return "6000.0.33f1"
2424
}
2525
Default {
2626
throw "Unkown variable '$name'"

scripts/ci-setup-java.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
param(
2+
[Parameter(Mandatory=$true)]
3+
[string]$UnityVersion
4+
)
5+
6+
function Test-JavaPath {
7+
param($Path, $Version)
8+
if (-not (Test-Path $Path)) {
9+
throw "Java $Version path not found at: $Path."
10+
}
11+
}
12+
13+
switch -Regex ($UnityVersion) {
14+
"2019" {
15+
Test-JavaPath $env:JAVA_HOME_8_X64 "8"
16+
$javaHome = $env:JAVA_HOME_8_X64
17+
Write-Host "Using Java 8 for Unity 2019"
18+
}
19+
"2022" {
20+
Test-JavaPath $env:JAVA_HOME_11_X64 "11"
21+
$javaHome = $env:JAVA_HOME_11_X64
22+
Write-Host "Using Java 11 for Unity 2022"
23+
}
24+
"6000" {
25+
Test-JavaPath $env:JAVA_HOME_17_X64 "17"
26+
$javaHome = $env:JAVA_HOME_17_X64
27+
Write-Host "Using Java 17 for Unity 6"
28+
}
29+
default {
30+
throw "Unexpected Unity version: $UnityVersion"
31+
}
32+
}
33+
34+
Write-Host "Selected JAVA_HOME: $javaHome"
35+
"JAVA_HOME=$javaHome" >> $env:GITHUB_ENV

scripts/smoke-test-android.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin
269269

270270
Write-Host "Starting app '$activityName'"
271271

272-
# Start the adb command as a background job with a 30-second timeout
272+
# Start the adb command as a background job so we can wait for it to finish with a timeout
273273
$job = Start-Job -ScriptBlock {
274274
param($device, $activityName, $Name)
275275
& adb -s $device shell am start -n $activityName -e test $Name -W 2>&1
276276
} -ArgumentList $device, $activityName, $Name
277277

278-
# Wait for the job to complete or timeout after 30 seconds
278+
# Wait for the job to complete or to timeout
279279
$completed = Wait-Job $job -Timeout 60
280280
if ($null -eq $completed) {
281281
Stop-Job $job
@@ -433,7 +433,7 @@ catch
433433
Write-Host "Caught exception: $_"
434434
Write-Host $_.ScriptStackTrace
435435
OnError $device $deviceApi
436-
return $false
436+
exit 1
437437
}
438438

439439
$failed = $false

src/Sentry.Unity.Android/SentryNativeAndroid.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,16 @@ public static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnit
121121

122122
internal static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo, RuntimePlatform platform)
123123
{
124+
options.DiagnosticLogger?.LogInfo("Attempting to close the Android SDK");
125+
124126
if (!sentryUnityInfo.IsNativeSupportEnabled(options, platform) || !SentryJava.IsSentryJavaPresent())
125127
{
126-
options.DiagnosticLogger?.LogDebug("Native Support is not enable. Skipping closing the native SDK");
128+
options.DiagnosticLogger?.LogDebug("Android Native Support is not enable. Skipping closing the Android SDK");
127129
return;
128130
}
129131

130132
// Sentry Native is initialized and closed by the Java SDK, no need to call into it directly
131-
options.DiagnosticLogger?.LogDebug("Closing the sentry-java SDK");
133+
options.DiagnosticLogger?.LogDebug("Closing the Android SDK");
132134

133135
// This is an edge-case where the Android SDK has been enabled and setup during build-time but is being
134136
// shut down at runtime. In this case Configure() has not been called and there is no JniExecutor yet

src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public static bool Init(SentryUnityOptions options)
6060
options.DiagnosticLogger?.LogDebug("Setting MaxCacheItems: {0}", options.MaxCacheItems);
6161
OptionsSetInt(cOptions, "maxCacheItems", options.MaxCacheItems);
6262

63-
StartWithOptions(cOptions);
64-
return true;
63+
var result = StartWithOptions(cOptions);
64+
return result is 1;
6565
}
6666

6767
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeLoadLibrary")]
@@ -80,7 +80,7 @@ public static bool Init(SentryUnityOptions options)
8080
private static extern void OptionsSetInt(IntPtr options, string name, int value);
8181

8282
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeStartWithOptions")]
83-
private static extern void StartWithOptions(IntPtr options);
83+
private static extern int StartWithOptions(IntPtr options);
8484

8585
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeCrashedLastRun")]
8686
public static extern int CrashedLastRun();

src/Sentry.Unity.iOS/SentryNativeCocoa.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ public static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnit
9898

9999
internal static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo, RuntimePlatform platform)
100100
{
101+
options.DiagnosticLogger?.LogInfo("Attempting to close the Cocoa SDK");
102+
101103
if (!sentryUnityInfo.IsNativeSupportEnabled(options, platform))
102104
{
103-
options.DiagnosticLogger?.LogDebug("Native Support is not enable. Skipping closing the native SDK");
105+
options.DiagnosticLogger?.LogDebug("Cocoa Native Support is not enable. Skipping closing the Cocoa SDK");
104106
return;
105107
}
106108

107-
options.DiagnosticLogger?.LogDebug("Closing the sentry-cocoa SDK");
109+
options.DiagnosticLogger?.LogDebug("Closing the Cocoa SDK");
108110
SentryCocoaBridgeProxy.Close();
109111
}
110112
}

src/Sentry.Unity/Integrations/AnrIntegration.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public void Register(IHub hub, SentryOptions sentryOptions)
4747

4848
internal abstract class AnrWatchDog
4949
{
50+
public const string Mechanism = "MainThreadWatchdog";
51+
5052
protected readonly int DetectionTimeoutMs;
5153
// Note: we don't sleep for the whole detection timeout or we wouldn't capture if the ANR started later.
5254
protected readonly int SleepIntervalMs;
@@ -78,7 +80,10 @@ protected void Report()
7880
{
7981
var message = $"Application not responding for at least {DetectionTimeoutMs} ms.";
8082
Logger?.LogInfo("Detected an ANR event: {0}", message);
81-
OnApplicationNotResponding?.Invoke(this, new ApplicationNotRespondingException(message));
83+
84+
var exception = new ApplicationNotRespondingException(message);
85+
exception.SetSentryMechanism(Mechanism, "Main thread unresponsive.", false);
86+
OnApplicationNotResponding?.Invoke(this, exception);
8287
}
8388
}
8489
}

src/Sentry.Unity/ScriptableSentryUnityOptions.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,24 @@ internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityIn
206206
new HttpStatusCodeRange(FailedRequestStatusCodes[i], FailedRequestStatusCodes[i + 1]));
207207
}
208208

209-
options.SetupLogging();
210-
211-
OptionsConfiguration?.Configure(options);
209+
if (OptionsConfiguration != null)
210+
{
211+
options.DiagnosticLogger?.LogDebug("OptionsConfiguration found. Calling configure.");
212+
OptionsConfiguration.Configure(options);
213+
}
212214

213215
// TODO: Deprecated and to be removed in the next major
216+
// This has to happen in between options object creation and updating the options based on programmatic changes
214217
if (RuntimeOptionsConfiguration != null && !isBuilding)
215218
{
216-
// This has to happen in between options object creation and updating the options based on programmatic changes
219+
options.DiagnosticLogger?.LogDebug("RuntimeOptionsConfiguration found. Calling configure.");
217220
RuntimeOptionsConfiguration.Configure(options);
218221
}
219222

223+
// We need to set up logging here because the configure callback might have changed the debug options.
224+
// Without setting up here we might miss out on logs between option-loading (now) and Init - i.e. native configuration
225+
options.SetupLogging();
226+
220227
if (!application.IsEditor && options.Il2CppLineNumberSupportEnabled && unityInfo is not null)
221228
{
222229
options.AddIl2CppExceptionProcessor(unityInfo);

0 commit comments

Comments
 (0)