Skip to content

Commit

Permalink
Make SDK unity-compatible (#2847)
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn authored Sep 8, 2023
1 parent 421d724 commit c383ed1
Show file tree
Hide file tree
Showing 56 changed files with 418 additions and 157 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Breaking changes:
- Bump min API to 19 ([#2883](https://github.com/getsentry/sentry-java/pull/2883))
- Fix don't overwrite the span status of unfinished spans ([#2859](https://github.com/getsentry/sentry-java/pull/2859))
- If you're using a self hosted version of sentry, sentry self hosted >= 22.12.0 is required
- Migrate from `default` interface methods to proper implementations in each interface implementor ([#2847](https://github.com/getsentry/sentry-java/pull/2847))
- This prevents issues when using the SDK on older AGP versions (< 4.x.x)
- Make sure to align Sentry dependencies to the same version when bumping the SDK to 7.+, otherwise it will crash at runtime due to binary incompatibility.
(E.g. if you're using `-timber`, `-okhttp` or other packages)

## 6.29.0

Expand Down
8 changes: 6 additions & 2 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public final class io/sentry/android/core/AnrIntegrationFactory {
public final class io/sentry/android/core/AnrV2EventProcessor : io/sentry/BackfillingEventProcessor {
public fun <init> (Landroid/content/Context;Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/core/BuildInfoProvider;)V
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
}

public class io/sentry/android/core/AnrV2Integration : io/sentry/Integration, java/io/Closeable {
Expand All @@ -73,6 +74,7 @@ public class io/sentry/android/core/AnrV2Integration : io/sentry/Integration, ja

public final class io/sentry/android/core/AnrV2Integration$AnrV2Hint : io/sentry/hints/BlockingFlushHint, io/sentry/hints/AbnormalExit, io/sentry/hints/Backfillable {
public fun <init> (JLio/sentry/ILogger;JZZ)V
public fun ignoreCurrentThread ()Z
public fun mechanism ()Ljava/lang/String;
public fun shouldEnrich ()Z
public fun timestamp ()Ljava/lang/Long;
Expand Down Expand Up @@ -205,9 +207,10 @@ public final class io/sentry/android/core/PhoneStateBreadcrumbsIntegration : io/
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
}

public final class io/sentry/android/core/ScreenshotEventProcessor : io/sentry/EventProcessor, io/sentry/IntegrationName {
public final class io/sentry/android/core/ScreenshotEventProcessor : io/sentry/EventProcessor {
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/core/BuildInfoProvider;)V
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
}

public final class io/sentry/android/core/SentryAndroid {
Expand Down Expand Up @@ -350,9 +353,10 @@ public final class io/sentry/android/core/UserInteractionIntegration : android/a
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
}

public final class io/sentry/android/core/ViewHierarchyEventProcessor : io/sentry/EventProcessor, io/sentry/IntegrationName {
public final class io/sentry/android/core/ViewHierarchyEventProcessor : io/sentry/EventProcessor {
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;)V
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
public static fun snapshotViewHierarchy (Landroid/app/Activity;Lio/sentry/ILogger;)Lio/sentry/protocol/ViewHierarchy;
public static fun snapshotViewHierarchy (Landroid/app/Activity;Ljava/util/List;Lio/sentry/util/thread/IMainThreadChecker;Lio/sentry/ILogger;)Lio/sentry/protocol/ViewHierarchy;
public static fun snapshotViewHierarchy (Landroid/view/View;)Lio/sentry/protocol/ViewHierarchy;
Expand Down
17 changes: 16 additions & 1 deletion sentry-android-core/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,22 @@
-keepattributes LineNumberTable,SourceFile

# Keep Classnames for integrations
-keepnames class * implements io.sentry.IntegrationName
-keepnames class * implements io.sentry.Integration

-dontwarn io.sentry.apollo.SentryApolloInterceptor
-keepnames class io.sentry.apollo.SentryApolloInterceptor

-dontwarn io.sentry.apollo3.SentryApollo3HttpInterceptor
-keepnames class io.sentry.apollo3.SentryApollo3HttpInterceptor

-dontwarn io.sentry.android.okhttp.SentryOkHttpInterceptor
-keepnames class io.sentry.android.okhttp.SentryOkHttpInterceptor

-dontwarn io.sentry.android.navigation.SentryNavigationListener
-keepnames class io.sentry.android.navigation.SentryNavigationListener

-keepnames class io.sentry.android.core.ScreenshotEventProcessor
-keepnames class io.sentry.android.core.ViewHierarchyEventProcessor

# Keep any custom option classes like SentryAndroidOptions, as they're loaded via reflection
# Also keep method names, as they're e.g. used by native via JNI calls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.sentry.MeasurementUnit.Duration.MILLISECOND;
import static io.sentry.TypeCheckHint.ANDROID_ACTIVITY;
import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import android.app.Activity;
import android.app.Application;
Expand Down Expand Up @@ -126,7 +127,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio

application.registerActivityLifecycleCallbacks(this);
this.options.getLogger().log(SentryLevel.DEBUG, "ActivityLifecycleIntegration installed.");
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
}

private boolean isPerformanceEnabled(final @NotNull SentryAndroidOptions options) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.sentry.android.core;

import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import android.annotation.SuppressLint;
import android.content.Context;
import io.sentry.Hint;
Expand Down Expand Up @@ -74,7 +76,7 @@ private void register(final @NotNull IHub hub, final @NotNull SentryAndroidOptio
anrWatchDog.start();

options.getLogger().log(SentryLevel.DEBUG, "AnrIntegration installed.");
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
}
}
}
Expand Down Expand Up @@ -161,5 +163,10 @@ public String mechanism() {
public boolean ignoreCurrentThread() {
return true;
}

@Override
public @Nullable Long timestamp() {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import io.sentry.protocol.SdkVersion;
import io.sentry.protocol.SentryStackTrace;
import io.sentry.protocol.SentryThread;
import io.sentry.protocol.SentryTransaction;
import io.sentry.protocol.User;
import io.sentry.util.HintUtils;
import java.util.ArrayList;
Expand Down Expand Up @@ -90,6 +91,15 @@ public AnrV2EventProcessor(
sentryExceptionFactory = new SentryExceptionFactory(sentryStackTraceFactory);
}

@Override
public @NotNull SentryTransaction process(
@NotNull SentryTransaction transaction, @NotNull Hint hint) {
// that's only necessary because on newer versions of Unity, if not overriding this method, it's
// throwing 'java.lang.AbstractMethodError: abstract method' and the reason is probably
// compilation mismatch
return transaction;
}

@Override
public @Nullable SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) {
final Object unwrappedHint = HintUtils.getSentrySdkHint(hint);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.sentry.android.core;

import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.ApplicationExitInfo;
Expand Down Expand Up @@ -93,7 +95,7 @@ public void register(@NotNull IHub hub, @NotNull SentryOptions options) {
options.getLogger().log(SentryLevel.DEBUG, "Failed to start AnrProcessor.", e);
}
options.getLogger().log(SentryLevel.DEBUG, "AnrV2Integration installed.");
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
}
}

Expand Down Expand Up @@ -365,6 +367,11 @@ public AnrV2Hint(
this.isBackgroundAnr = isBackgroundAnr;
}

@Override
public boolean ignoreCurrentThread() {
return false;
}

@Override
public Long timestamp() {
return timestamp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sentry.android.core;

import static io.sentry.TypeCheckHint.ANDROID_CONFIGURATION;
import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import android.content.ComponentCallbacks2;
import android.content.Context;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
options
.getLogger()
.log(SentryLevel.DEBUG, "AppComponentsBreadcrumbsIntegration installed.");
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
} catch (Throwable e) {
this.options.setEnableAppComponentBreadcrumbs(false);
options.getLogger().log(SentryLevel.INFO, e, "ComponentCallbacks2 is not available.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.sentry.android.core;

import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import androidx.lifecycle.ProcessLifecycleOwner;
import io.sentry.IHub;
import io.sentry.Integration;
Expand Down Expand Up @@ -94,7 +96,7 @@ private void addObserver(final @NotNull IHub hub) {
try {
ProcessLifecycleOwner.get().getLifecycle().addObserver(watcher);
options.getLogger().log(SentryLevel.DEBUG, "AppLifecycleIntegration installed.");
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
} catch (Throwable e) {
// This is to handle a potential 'AbstractMethodError' gracefully. The error is triggered in
// connection with conflicting dependencies of the androidx.lifecycle.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.sentry.android.core;

import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import io.sentry.IHub;
import io.sentry.Integration;
import io.sentry.SentryLevel;
Expand Down Expand Up @@ -53,7 +55,7 @@ public final void register(final @NotNull IHub hub, final @NotNull SentryOptions
method.invoke(null, args);

this.options.getLogger().log(SentryLevel.DEBUG, "NdkIntegration installed.");
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
} catch (NoSuchMethodException e) {
disableNdkIntegration(this.options);
this.options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.sentry.android.core;

import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import android.annotation.SuppressLint;
import android.content.Context;
import android.net.ConnectivityManager;
Expand Down Expand Up @@ -79,7 +81,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
return;
}
logger.log(SentryLevel.DEBUG, "NetworkBreadcrumbsIntegration installed.");
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sentry.android.core;

import static android.Manifest.permission.READ_PHONE_STATE;
import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import android.content.Context;
import android.telephony.TelephonyManager;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
telephonyManager.listen(listener, android.telephony.PhoneStateListener.LISTEN_CALL_STATE);

options.getLogger().log(SentryLevel.DEBUG, "PhoneStateBreadcrumbsIntegration installed.");
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
} catch (Throwable e) {
this.options
.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import static io.sentry.TypeCheckHint.ANDROID_ACTIVITY;
import static io.sentry.android.core.internal.util.ScreenshotUtils.takeScreenshot;
import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import android.app.Activity;
import io.sentry.Attachment;
import io.sentry.EventProcessor;
import io.sentry.Hint;
import io.sentry.IntegrationName;
import io.sentry.SentryEvent;
import io.sentry.SentryLevel;
import io.sentry.android.core.internal.util.AndroidCurrentDateProvider;
import io.sentry.android.core.internal.util.Debouncer;
import io.sentry.protocol.SentryTransaction;
import io.sentry.util.HintUtils;
import io.sentry.util.Objects;
import org.jetbrains.annotations.ApiStatus;
Expand All @@ -23,7 +24,7 @@
* captured.
*/
@ApiStatus.Internal
public final class ScreenshotEventProcessor implements EventProcessor, IntegrationName {
public final class ScreenshotEventProcessor implements EventProcessor {

private final @NotNull SentryAndroidOptions options;
private final @NotNull BuildInfoProvider buildInfoProvider;
Expand All @@ -40,10 +41,19 @@ public ScreenshotEventProcessor(
this.debouncer = new Debouncer(AndroidCurrentDateProvider.getInstance(), DEBOUNCE_WAIT_TIME_MS);

if (options.isAttachScreenshot()) {
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
}
}

@Override
public @NotNull SentryTransaction process(
@NotNull SentryTransaction transaction, @NotNull Hint hint) {
// that's only necessary because on newer versions of Unity, if not overriding this method, it's
// throwing 'java.lang.AbstractMethodError: abstract method' and the reason is probably
// compilation mismatch
return transaction;
}

@Override
public @NotNull SentryEvent process(final @NotNull SentryEvent event, final @NotNull Hint hint) {
if (!event.isErrored()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static android.content.Intent.ACTION_TIMEZONE_CHANGED;
import static android.content.Intent.ACTION_TIME_CHANGED;
import static io.sentry.TypeCheckHint.ANDROID_INTENT;
import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import android.content.BroadcastReceiver;
import android.content.Context;
Expand Down Expand Up @@ -103,7 +104,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
this.options
.getLogger()
.log(SentryLevel.DEBUG, "SystemEventsBreadcrumbsIntegration installed.");
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
} catch (Throwable e) {
this.options.setEnableSystemEventBreadcrumbs(false);
this.options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static android.content.Context.SENSOR_SERVICE;
import static io.sentry.TypeCheckHint.ANDROID_SENSOR_EVENT;
import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import android.content.Context;
import android.hardware.Sensor;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
options
.getLogger()
.log(SentryLevel.DEBUG, "TempSensorBreadcrumbsIntegration installed.");
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
} else {
this.options
.getLogger()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.sentry.android.core;

import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
Expand Down Expand Up @@ -119,7 +121,7 @@ public void register(@NotNull IHub hub, @NotNull SentryOptions options) {
if (isAndroidXAvailable) {
application.registerActivityLifecycleCallbacks(this);
this.options.getLogger().log(SentryLevel.DEBUG, "UserInteractionIntegration installed.");
addIntegrationToSdkVersion();
addIntegrationToSdkVersion(getClass());
} else {
options
.getLogger()
Expand Down
Loading

0 comments on commit c383ed1

Please sign in to comment.