Skip to content

Commit 1bd5185

Browse files
marandanetoromtsn
andauthored
Allow optimization and obfuscation of the SDK by reducing proguard rules (#2031)
Co-authored-by: Roman Zavarnitsyn <[email protected]>
1 parent f57d435 commit 1bd5185

File tree

7 files changed

+53
-39
lines changed

7 files changed

+53
-39
lines changed

CHANGELOG.md

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

33
## Unreleased
44

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

710
- Calling Sentry.init and specifying contextTags now has an effect on the Logback SentryAppender ([#2052](https://github.com/getsentry/sentry-java/pull/2052))
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1+
##---------------Begin: proguard configuration for android-core ----------
2+
13
##---------------Begin: proguard configuration for androidx.core ----------
24
-keep class androidx.core.view.GestureDetectorCompat { <init>(...); }
35
-keep class androidx.core.app.FrameMetricsAggregator { <init>(...); }
46
-keep interface androidx.core.view.ScrollingView { *; }
57
##---------------End: proguard configuration for androidx.core ----------
68

7-
##---------------Begin: proguard configuration for Gson ----------
8-
# Gson uses generic type information stored in a class file when working with fields. Proguard
9-
# removes such information by default, so configure it to keep all of it.
10-
-keepattributes Signature
11-
12-
# For using GSON @Expose annotation
13-
-keepattributes *Annotation*
14-
15-
# Application classes that will be serialized/deserialized
16-
-keep class io.sentry.** { *; }
17-
-keepclassmembers enum io.sentry.** { *; }
18-
-keep class io.sentry.android.core.** { *; }
9+
##---------------Begin: proguard configuration for androidx.lifecycle ----------
10+
-keep interface androidx.lifecycle.DefaultLifecycleObserver { *; }
11+
-keep class androidx.lifecycle.ProcessLifecycleOwner { <init>(...); }
12+
##---------------End: proguard configuration for androidx.lifecycle ----------
1913

2014
# don't warn jetbrains annotations
2115
-dontwarn org.jetbrains.annotations.**
22-
23-
# R8: Attribute Signature requires InnerClasses attribute. Check -keepattributes directive.
24-
-keepattributes InnerClasses
16+
# don't warn about missing classes (mainly for Guardsquare's proguard).
17+
# We are checking for their presence at runtime
18+
-dontwarn io.sentry.android.timber.SentryTimberIntegration
19+
-dontwarn io.sentry.android.fragment.FragmentLifecycleIntegration
2520

2621
# To ensure that stack traces is unambiguous
2722
# https://developer.android.com/studio/build/shrink-code#decode-stack-trace
2823
-keepattributes LineNumberTable,SourceFile
24+
25+
##---------------End: proguard configuration for android-core ----------
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
-keep class io.sentry.android.fragment.** { *; }
1+
##---------------Begin: proguard configuration for Fragment ----------
2+
3+
# The Android SDK checks at runtime if this class is available via Class.forName
4+
-keep class io.sentry.android.fragment.FragmentLifecycleIntegration { <init>(...); }
25

36
# To ensure that stack traces is unambiguous
47
# https://developer.android.com/studio/build/shrink-code#decode-stack-trace
58
-keepattributes LineNumberTable,SourceFile
9+
10+
##---------------End: proguard configuration for Fragment ----------

sentry-android-ndk/proguard-rules.pro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
##---------------Begin: proguard configuration for NDK ----------
22

3-
-keep class io.sentry.android.ndk.** { *; }
3+
# The Android SDK checks at runtime if this class is available via Class.forName
4+
-keep class io.sentry.android.ndk.SentryNdk { *; }
5+
# The JNI layer uses this classes through reflection
6+
-keep class io.sentry.android.core.SentryAndroidOptions { *; }
7+
-keep class io.sentry.protocol.DebugImage { *; }
48

59
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
610
-keepclasseswithmembernames,includedescriptorclasses class * {
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
##---------------Begin: proguard configuration for OkHttp ----------
22

3-
-keep class io.sentry.android.okhttp.** { *; }
4-
53
# To ensure that stack traces is unambiguous
64
# https://developer.android.com/studio/build/shrink-code#decode-stack-trace
75
-keepattributes LineNumberTable,SourceFile
86

9-
# https://square.github.io/okhttp/r8_proguard/
10-
# JSR 305 annotations are for embedding nullability information.
11-
-dontwarn javax.annotation.**
12-
13-
# A resource is loaded with a relative path so the package of this class must be preserved.
14-
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
15-
16-
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
17-
-dontwarn org.codehaus.mojo.animal_sniffer.*
18-
19-
# OkHttp platform used only on JVM and when Conscrypt dependency is available.
20-
-dontwarn okhttp3.internal.platform.ConscryptPlatform
21-
-dontwarn org.conscrypt.ConscryptHostnameVerifier
7+
# https://square.github.io/okhttp/features/r8_proguard/
8+
# If you use OkHttp as a dependency in an Android project which uses R8 as a default compiler you
9+
# don’t have to do anything. The specific rules are already bundled into the JAR which can
10+
# be interpreted by R8 automatically.
11+
# https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/jvmMain/resources/META-INF/proguard/okhttp3.pro
2212

2313
##---------------End: proguard configuration for OkHttp ----------

sentry-android-timber/proguard-rules.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
##---------------Begin: proguard configuration for Timber ----------
22

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

56
# To ensure that stack traces is unambiguous
67
# https://developer.android.com/studio/build/shrink-code#decode-stack-trace

sentry-samples/sentry-samples-android/proguard-rules.pro

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,24 @@
1212
# public *;
1313
#}
1414

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

19-
# If you keep the line number information, uncomment this to
20-
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
19+
20+
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
21+
-keepclasseswithmembernames,includedescriptorclasses class * {
22+
native <methods>;
23+
}
24+
25+
# Please add these rules to your existing keep rules in order to suppress warnings.
26+
# This is generated automatically by the Android Gradle plugin.
27+
-dontwarn org.bouncycastle.jsse.BCSSLParameters
28+
-dontwarn org.bouncycastle.jsse.BCSSLSocket
29+
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
30+
-dontwarn org.conscrypt.Conscrypt$Version
31+
-dontwarn org.conscrypt.Conscrypt
32+
-dontwarn org.conscrypt.ConscryptHostnameVerifier
33+
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
34+
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
35+
-dontwarn org.openjsse.net.ssl.OpenJSSE

0 commit comments

Comments
 (0)