Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optimization and obfuscation of the SDK by reducing proguard rules #2031

Merged
merged 7 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Features
- Allow optimization and obfuscation of the SDK by reducing proguard rules ([#2031](https://github.com/getsentry/sentry-java/pull/2031))

### Fixes

- Calling Sentry.init and specifying contextTags now has an effect on the Logback SentryAppender ([#2052](https://github.com/getsentry/sentry-java/pull/2052))
Expand Down
27 changes: 12 additions & 15 deletions sentry-android-core/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
##---------------Begin: proguard configuration for android-core ----------

##---------------Begin: proguard configuration for androidx.core ----------
-keep class androidx.core.view.GestureDetectorCompat { <init>(...); }
-keep class androidx.core.app.FrameMetricsAggregator { <init>(...); }
-keep interface androidx.core.view.ScrollingView { *; }
##---------------End: proguard configuration for androidx.core ----------

##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Application classes that will be serialized/deserialized
-keep class io.sentry.** { *; }
-keepclassmembers enum io.sentry.** { *; }
-keep class io.sentry.android.core.** { *; }
##---------------Begin: proguard configuration for androidx.lifecycle ----------
-keep interface androidx.lifecycle.DefaultLifecycleObserver { *; }
-keep class androidx.lifecycle.ProcessLifecycleOwner { <init>(...); }
##---------------End: proguard configuration for androidx.lifecycle ----------

# don't warn jetbrains annotations
-dontwarn org.jetbrains.annotations.**

# R8: Attribute Signature requires InnerClasses attribute. Check -keepattributes directive.
-keepattributes InnerClasses
# don't warn about missing classes (mainly for Guardsquare's proguard).
# We are checking for their presence at runtime
-dontwarn io.sentry.android.timber.SentryTimberIntegration
-dontwarn io.sentry.android.fragment.FragmentLifecycleIntegration

# To ensure that stack traces is unambiguous
# https://developer.android.com/studio/build/shrink-code#decode-stack-trace
-keepattributes LineNumberTable,SourceFile

##---------------End: proguard configuration for android-core ----------
7 changes: 6 additions & 1 deletion sentry-android-fragment/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
-keep class io.sentry.android.fragment.** { *; }
##---------------Begin: proguard configuration for Fragment ----------

# The Android SDK checks at runtime if this class is available via Class.forName
-keep class io.sentry.android.fragment.FragmentLifecycleIntegration { <init>(...); }

# To ensure that stack traces is unambiguous
# https://developer.android.com/studio/build/shrink-code#decode-stack-trace
-keepattributes LineNumberTable,SourceFile

##---------------End: proguard configuration for Fragment ----------
6 changes: 5 additions & 1 deletion sentry-android-ndk/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
##---------------Begin: proguard configuration for NDK ----------

-keep class io.sentry.android.ndk.** { *; }
# The Android SDK checks at runtime if this class is available via Class.forName
-keep class io.sentry.android.ndk.SentryNdk { *; }
# The JNI layer uses this classes through reflection
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
-keep class io.sentry.android.core.SentryAndroidOptions { *; }
-keep class io.sentry.protocol.DebugImage { *; }

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames,includedescriptorclasses class * {
Expand Down
20 changes: 5 additions & 15 deletions sentry-android-okhttp/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
##---------------Begin: proguard configuration for OkHttp ----------

-keep class io.sentry.android.okhttp.** { *; }

# To ensure that stack traces is unambiguous
# https://developer.android.com/studio/build/shrink-code#decode-stack-trace
-keepattributes LineNumberTable,SourceFile

# https://square.github.io/okhttp/r8_proguard/
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase

# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*

# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform
-dontwarn org.conscrypt.ConscryptHostnameVerifier
# https://square.github.io/okhttp/features/r8_proguard/
# If you use OkHttp as a dependency in an Android project which uses R8 as a default compiler you
# don’t have to do anything. The specific rules are already bundled into the JAR which can
# be interpreted by R8 automatically.
# https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/jvmMain/resources/META-INF/proguard/okhttp3.pro

##---------------End: proguard configuration for OkHttp ----------
3 changes: 2 additions & 1 deletion sentry-android-timber/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
##---------------Begin: proguard configuration for Timber ----------

-keep class io.sentry.android.timber.** { *; }
# The Android SDK checks at runtime if this class is available via Class.forName
-keep class io.sentry.android.timber.SentryTimberIntegration { <init>(...); }

# To ensure that stack traces is unambiguous
# https://developer.android.com/studio/build/shrink-code#decode-stack-trace
Expand Down
26 changes: 20 additions & 6 deletions sentry-samples/sentry-samples-android/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,24 @@
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# To ensure that stack traces is unambiguous
# https://developer.android.com/studio/build/shrink-code#decode-stack-trace
-keepattributes LineNumberTable,SourceFile

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames,includedescriptorclasses class * {
native <methods>;
}

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn org.bouncycastle.jsse.BCSSLParameters
-dontwarn org.bouncycastle.jsse.BCSSLSocket
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
-dontwarn org.conscrypt.Conscrypt$Version
-dontwarn org.conscrypt.Conscrypt
-dontwarn org.conscrypt.ConscryptHostnameVerifier
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
-dontwarn org.openjsse.net.ssl.OpenJSSE