From 597aa6e5a20e7d9e0cb5e19460f39ab2b5ed6186 Mon Sep 17 00:00:00 2001 From: Francisco Prieto Date: Fri, 28 Jun 2024 15:38:05 -0300 Subject: [PATCH 1/9] Removed unused java9 proguard configuration --- embrace-android-sdk/embrace-proguard.cfg | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/embrace-android-sdk/embrace-proguard.cfg b/embrace-android-sdk/embrace-proguard.cfg index 3f7c56175e..3dca0967bf 100644 --- a/embrace-android-sdk/embrace-proguard.cfg +++ b/embrace-android-sdk/embrace-proguard.cfg @@ -8,13 +8,11 @@ -dontwarn okhttp3.** -dontwarn okio.** -## Proguard configuration for Arrow --keep class java9.** { *; } --dontwarn java9.** - ## OpenTelemetry Java SDK -keep class io.opentelemetry.api.trace.StatusCode { *; } --dontwarn com.google.auto.value.AutoValue$CopyAnnotations -dontwarn com.google.auto.value.extension.memoized.Memoized + +## Annotations used by some dependencies (such as OTel, Protobuf and Moshi) at compile time. No need to keep them for runtime. -dontwarn com.google.auto.value.AutoValue +-dontwarn com.google.auto.value.AutoValue$CopyAnnotations -dontwarn com.google.errorprone.annotations.MustBeClosed \ No newline at end of file From 499c460bedc9e3f7af4ed77114f544380abee838 Mon Sep 17 00:00:00 2001 From: Francisco Prieto Date: Mon, 1 Jul 2024 14:44:39 -0300 Subject: [PATCH 2/9] Removed unnecessary "don't keep" okhttp3 and okio proguard directives --- embrace-android-sdk/embrace-proguard.cfg | 4 ---- 1 file changed, 4 deletions(-) diff --git a/embrace-android-sdk/embrace-proguard.cfg b/embrace-android-sdk/embrace-proguard.cfg index 3dca0967bf..c72d0de737 100644 --- a/embrace-android-sdk/embrace-proguard.cfg +++ b/embrace-android-sdk/embrace-proguard.cfg @@ -4,10 +4,6 @@ -keep class io.embrace.android.embracesdk.** { *; } -dontwarn io.embrace.android.embracesdk.** -## Proguard configuration for OkHTTP3 / Okio --dontwarn okhttp3.** --dontwarn okio.** - ## OpenTelemetry Java SDK -keep class io.opentelemetry.api.trace.StatusCode { *; } -dontwarn com.google.auto.value.extension.memoized.Memoized From 6ad0ec5d54f094f438f90e2d91b8fa44cdfee77d Mon Sep 17 00:00:00 2001 From: Francisco Prieto Date: Mon, 1 Jul 2024 18:02:01 -0300 Subject: [PATCH 3/9] Remove unnecessary attributes kept in proguard: Exceptions, InnerClasses, Signature We only need to keep LineNumberTable and SourceFile for showing crash stacktraces. --- embrace-android-sdk/embrace-proguard.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embrace-android-sdk/embrace-proguard.cfg b/embrace-android-sdk/embrace-proguard.cfg index c72d0de737..7276fa4b07 100644 --- a/embrace-android-sdk/embrace-proguard.cfg +++ b/embrace-android-sdk/embrace-proguard.cfg @@ -1,4 +1,4 @@ --keepattributes Exceptions, InnerClasses, Signature, LineNumberTable, SourceFile +-keepattributes LineNumberTable, SourceFile ## Proguard configuration for Embrace -keep class io.embrace.android.embracesdk.** { *; } From 76d77e09a77aa30660666abc456b7bccdc572a8a Mon Sep 17 00:00:00 2001 From: Francisco Prieto Date: Tue, 2 Jul 2024 17:18:14 -0300 Subject: [PATCH 4/9] Added -keep okhttp3.OkHttp to fetch okhttp version on minified builds --- embrace-android-sdk/embrace-proguard.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/embrace-android-sdk/embrace-proguard.cfg b/embrace-android-sdk/embrace-proguard.cfg index 7276fa4b07..58a904f777 100644 --- a/embrace-android-sdk/embrace-proguard.cfg +++ b/embrace-android-sdk/embrace-proguard.cfg @@ -8,6 +8,10 @@ -keep class io.opentelemetry.api.trace.StatusCode { *; } -dontwarn com.google.auto.value.extension.memoized.Memoized +## Keep OkHttp class so we can fetch the version correctly via reflection. +-keep class okhttp3.OkHttp { *; } +-keep class okhttp3.OkHttpClient { *; } + ## Annotations used by some dependencies (such as OTel, Protobuf and Moshi) at compile time. No need to keep them for runtime. -dontwarn com.google.auto.value.AutoValue -dontwarn com.google.auto.value.AutoValue$CopyAnnotations From 158cc5a955f9efa1a35b06db885e225770328f1b Mon Sep 17 00:00:00 2001 From: Francisco Prieto Date: Wed, 3 Jul 2024 11:36:11 -0300 Subject: [PATCH 5/9] Added @JsonClass(generateAdapter = false) to enums https://github.com/square/moshi/tree/master?tab=readme-ov-file#enums --- .../src/main/java/io/embrace/android/embracesdk/EventType.kt | 2 ++ .../android/embracesdk/capture/metadata/AppEnvironment.kt | 2 ++ .../android/embracesdk/internal/payload/EnvelopeResource.kt | 1 + .../java/io/embrace/android/embracesdk/internal/payload/Span.kt | 1 + .../java/io/embrace/android/embracesdk/payload/LifeEventType.kt | 2 ++ .../java/io/embrace/android/embracesdk/payload/TapBreadcrumb.kt | 1 + 6 files changed, 9 insertions(+) diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EventType.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EventType.kt index 3d50bc55fb..f4e4b06a34 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EventType.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EventType.kt @@ -2,6 +2,7 @@ package io.embrace.android.embracesdk import android.annotation.SuppressLint import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass import io.embrace.android.embracesdk.annotation.InternalApi /** @@ -9,6 +10,7 @@ import io.embrace.android.embracesdk.annotation.InternalApi */ @InternalApi @SuppressLint("EmbracePublicApiPackageRule") +@JsonClass(generateAdapter = false) internal enum class EventType( /** diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/AppEnvironment.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/AppEnvironment.kt index b289dc5d6c..254ca7e405 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/AppEnvironment.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/AppEnvironment.kt @@ -2,12 +2,14 @@ package io.embrace.android.embracesdk.capture.metadata import android.content.pm.ApplicationInfo import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass internal class AppEnvironment(appInfo: ApplicationInfo) { val isDebug: Boolean = with(appInfo) { flags and ApplicationInfo.FLAG_DEBUGGABLE != 0 } val environment: Environment = if (isDebug) Environment.DEV else Environment.PROD + @JsonClass(generateAdapter = false) internal enum class Environment(val value: String) { @Json(name = "dev") DEV("dev"), diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/EnvelopeResource.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/EnvelopeResource.kt index 818473f78d..11347e4d97 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/EnvelopeResource.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/EnvelopeResource.kt @@ -198,6 +198,7 @@ internal data class EnvelopeResource( * * Values: NATIVE,REACT_NATIVE,UNITY,FLUTTER */ + @JsonClass(generateAdapter = false) internal enum class AppFramework(val value: Int) { @Json(name = "1") NATIVE(1), diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/Span.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/Span.kt index e1316450a7..9b4d2d4ec6 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/Span.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/Span.kt @@ -61,6 +61,7 @@ internal data class Span( * * Values: UNSET,ERROR,OK */ + @JsonClass(generateAdapter = false) internal enum class Status(val value: String) { @Json(name = "Unset") UNSET("Unset"), diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/LifeEventType.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/LifeEventType.kt index 0bfc3c7bb2..7195ccade6 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/LifeEventType.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/LifeEventType.kt @@ -1,10 +1,12 @@ package io.embrace.android.embracesdk.payload import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass /** * Enum to discriminate the different ways a session can start / end */ +@JsonClass(generateAdapter = false) internal enum class LifeEventType { /* Session values */ diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/TapBreadcrumb.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/TapBreadcrumb.kt index df3e8770b4..174918ad25 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/TapBreadcrumb.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/TapBreadcrumb.kt @@ -50,6 +50,7 @@ internal class TapBreadcrumb( override fun getStartTime(): Long = timestamp + @JsonClass(generateAdapter = false) internal enum class TapBreadcrumbType(val value: String) { @Json(name = "s") TAP("tap"), From da59afe7e9fc0bcf1a79ec49fd133aecb89ccb5d Mon Sep 17 00:00:00 2001 From: Francisco Prieto Date: Wed, 3 Jul 2024 15:36:45 -0300 Subject: [PATCH 6/9] Added proguard rules to keep public classes used by hosted SDKs --- embrace-android-sdk/embrace-proguard.cfg | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/embrace-android-sdk/embrace-proguard.cfg b/embrace-android-sdk/embrace-proguard.cfg index 58a904f777..4bda96338f 100644 --- a/embrace-android-sdk/embrace-proguard.cfg +++ b/embrace-android-sdk/embrace-proguard.cfg @@ -1,8 +1,13 @@ -keepattributes LineNumberTable, SourceFile -## Proguard configuration for Embrace --keep class io.embrace.android.embracesdk.** { *; } --dontwarn io.embrace.android.embracesdk.** +## Keep classes used by hosted SDKs +-keep class io.embrace.android.embracesdk.Embrace { *; } +-keep class io.embrace.android.embracesdk.Embrace$AppFramework { *; } +-keep class io.embrace.android.embracesdk.Embrace$LastRunEndState { *; } +-keep class io.embrace.android.embracesdk.Severity { *; } +-keep public class * implements io.embrace.android.embracesdk.internal.EmbraceInternalInterface { + *; +} ## OpenTelemetry Java SDK -keep class io.opentelemetry.api.trace.StatusCode { *; } From a54a5927c47665b49bb4e5a4b95859791104e459 Mon Sep 17 00:00:00 2001 From: Francisco Prieto Date: Wed, 3 Jul 2024 15:52:43 -0300 Subject: [PATCH 7/9] Added proguard rules to keep classes used by native code --- embrace-android-sdk/embrace-proguard.cfg | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/embrace-android-sdk/embrace-proguard.cfg b/embrace-android-sdk/embrace-proguard.cfg index 4bda96338f..400d229f42 100644 --- a/embrace-android-sdk/embrace-proguard.cfg +++ b/embrace-android-sdk/embrace-proguard.cfg @@ -5,9 +5,12 @@ -keep class io.embrace.android.embracesdk.Embrace$AppFramework { *; } -keep class io.embrace.android.embracesdk.Embrace$LastRunEndState { *; } -keep class io.embrace.android.embracesdk.Severity { *; } --keep public class * implements io.embrace.android.embracesdk.internal.EmbraceInternalInterface { - *; -} +-keep public class * implements io.embrace.android.embracesdk.internal.EmbraceInternalInterface { *; } + +## Keep classes used from native code +-keep class io.embrace.android.embracesdk.payload.NativeThreadAnrSample { *; } +-keep class io.embrace.android.embracesdk.payload.NativeThreadAnrStackframe { *; } +-keep class io.embrace.android.embracesdk.anr.sigquit.SigquitDataSource { *; } ## OpenTelemetry Java SDK -keep class io.opentelemetry.api.trace.StatusCode { *; } From 118eaeb3879e38506352202c180d85a65137db80 Mon Sep 17 00:00:00 2001 From: Francisco Prieto Date: Wed, 3 Jul 2024 20:02:54 -0300 Subject: [PATCH 8/9] Added proguard rules to keep swazzler hooks --- embrace-android-sdk/embrace-proguard.cfg | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/embrace-android-sdk/embrace-proguard.cfg b/embrace-android-sdk/embrace-proguard.cfg index 400d229f42..65229f270a 100644 --- a/embrace-android-sdk/embrace-proguard.cfg +++ b/embrace-android-sdk/embrace-proguard.cfg @@ -23,4 +23,11 @@ ## Annotations used by some dependencies (such as OTel, Protobuf and Moshi) at compile time. No need to keep them for runtime. -dontwarn com.google.auto.value.AutoValue -dontwarn com.google.auto.value.AutoValue$CopyAnnotations --dontwarn com.google.errorprone.annotations.MustBeClosed \ No newline at end of file +-dontwarn com.google.errorprone.annotations.MustBeClosed + +## Keep swazzler hooks +-keep class io.embrace.android.embracesdk.okhttp3.** { *; } +-keep class io.embrace.android.embracesdk.ViewSwazzledHooks { *; } +-keep class io.embrace.android.embracesdk.WebViewClientSwazzledHooks { *; } +-keep class io.embrace.android.embracesdk.WebViewChromeClientSwazzledHooks { *; } +-keep class io.embrace.android.embracesdk.fcm.swazzle.callback.com.android.fcm.FirebaseSwazzledHooks { *; } From 41c2c636962121b93bfecdc520c757e58566ba68 Mon Sep 17 00:00:00 2001 From: Francisco Prieto Date: Fri, 5 Jul 2024 15:45:10 -0300 Subject: [PATCH 9/9] Added proguard rules for keeping classes with JNI calls to native code --- embrace-android-sdk/embrace-proguard.cfg | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/embrace-android-sdk/embrace-proguard.cfg b/embrace-android-sdk/embrace-proguard.cfg index 65229f270a..582218dd5f 100644 --- a/embrace-android-sdk/embrace-proguard.cfg +++ b/embrace-android-sdk/embrace-proguard.cfg @@ -12,6 +12,11 @@ -keep class io.embrace.android.embracesdk.payload.NativeThreadAnrStackframe { *; } -keep class io.embrace.android.embracesdk.anr.sigquit.SigquitDataSource { *; } +## Keep classes with JNI calls to native code +-keep class io.embrace.android.embracesdk.capture.cpu.EmbraceCpuInfoDelegate { *; } +-keep class io.embrace.android.embracesdk.anr.ndk.NativeThreadSamplerNdkDelegate { *; } +-keep class io.embrace.android.embracesdk.ndk.NdkDelegateImpl { *; } + ## OpenTelemetry Java SDK -keep class io.opentelemetry.api.trace.StatusCode { *; } -dontwarn com.google.auto.value.extension.memoized.Memoized