Skip to content

Commit 6e77419

Browse files
authored
fix(proguard): fix gson proguard rules and clean up other rules (#383)
- Fix proguard rules for GSON to one recommended by the GSON repo (https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg) - Clean up other proguard files.
1 parent 97298b8 commit 6e77419

File tree

13 files changed

+34
-142
lines changed

13 files changed

+34
-142
lines changed

android-sdk/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ android {
2929
versionName version_name
3030
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
3131
buildConfigField "String", "CLIENT_VERSION", "\"$version_name\""
32+
// these rules will be merged to app's proguard rules
3233
consumerProguardFiles '../proguard-rules.txt'
3334
}
3435
testOptions {
@@ -37,7 +38,6 @@ android {
3738
buildTypes {
3839
release {
3940
minifyEnabled false
40-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4141
}
4242
debug {
4343
testCoverageEnabled true

android-sdk/proguard-rules.pro

Lines changed: 0 additions & 17 deletions
This file was deleted.

datafile-handler/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ android {
2828
versionCode 1
2929
versionName version_name
3030
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
31-
consumerProguardFiles '../proguard-rules.txt'
3231
}
3332
testOptions {
3433
unitTests.returnDefaultValues = true
3534
}
3635
buildTypes {
3736
release {
3837
minifyEnabled false
39-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4038
}
4139
debug {
4240
testCoverageEnabled true

datafile-handler/proguard-rules.pro

Lines changed: 0 additions & 25 deletions
This file was deleted.

event-handler/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ android {
2828
versionCode 1
2929
versionName "1.0"
3030
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
31-
consumerProguardFiles '../proguard-rules.txt'
3231
}
3332
testOptions {
3433
unitTests.returnDefaultValues = true
3534
}
3635
buildTypes {
3736
release {
3837
minifyEnabled false
39-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4038
}
4139
debug {
4240
testCoverageEnabled true

event-handler/proguard-rules.pro

Lines changed: 0 additions & 17 deletions
This file was deleted.

proguard-rules.txt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040
-keep class com.optimizely.ab.bucketing.DecisionService { *; }
4141
-keep class com.optimizely.ab.Optimizely { *; }
4242

43-
# Gson
44-
-keepnames class com.google.gson.Gson
45-
4643
# Safely ignore warnings about other libraries since we are using Gson
4744
-dontwarn com.fasterxml.jackson.**
4845
-dontwarn org.json.**
@@ -65,3 +62,32 @@
6562
-dontwarn com.google.gson.**
6663
-dontwarn com.optimizely.ab.config.parser.**
6764

65+
# Gson (https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg)
66+
##---------------Begin: proguard configuration for Gson ----------
67+
# Gson uses generic type information stored in a class file when working with fields. Proguard
68+
# removes such information by default, so configure it to keep all of it.
69+
-keepattributes Signature
70+
71+
# For using GSON @Expose annotation
72+
-keepattributes *Annotation*
73+
74+
# Gson specific classes
75+
-dontwarn sun.misc.**
76+
77+
# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
78+
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
79+
-keep class * extends com.google.gson.TypeAdapter
80+
-keep class * implements com.google.gson.TypeAdapterFactory
81+
-keep class * implements com.google.gson.JsonSerializer
82+
-keep class * implements com.google.gson.JsonDeserializer
83+
84+
# Prevent R8 from leaving Data object members always null
85+
-keepclassmembers,allowobfuscation class * {
86+
@com.google.gson.annotations.SerializedName <fields>;
87+
}
88+
89+
# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
90+
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
91+
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
92+
##---------------End: proguard configuration for Gson ----------
93+

shared/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ android {
2828
versionCode 1
2929
versionName "1.0"
3030
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
31-
consumerProguardFiles '../proguard-rules.txt'
3231
}
3332
testOptions {
3433
unitTests.returnDefaultValues = true
3534
}
3635
buildTypes {
3736
release {
3837
minifyEnabled false
39-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4038
}
4139
debug {
4240
testCoverageEnabled true

shared/proguard-rules.pro

Lines changed: 0 additions & 17 deletions
This file was deleted.

test-app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ dependencies {
5050
// implementation "com.optimizely.ab:android-sdk:1.0.0"
5151
implementation "androidx.appcompat:appcompat:1.2.0"
5252
implementation "com.google.android.material:material:1.2.1"
53-
// EXAMPLE REPLACE noveogroup android-looger with slf4j-android logger
53+
// EXAMPLE - replace noveogroup android-looger with slf4j-android logger
5454
// https://mvnrepository.com/artifact/org.slf4j/slf4j-android
5555
//implementation "org.slf4j:slf4j-android:1.7.25"
56-
// EXAMPLE REPLACE gson json parsing with jackson-databind json parsing.
56+
// EXAMPLE - replace gson with jackson-databind json parser
5757
implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonversion"
5858

5959
// required by API-16

test-app/proguard-rules.pro

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,7 @@
77
# For more details, see
88
# http://developer.android.com/guide/developing/tools/proguard.html
99

10-
# Add any project specific keep options here:
11-
12-
# If your project uses WebView with JS, uncomment the following
13-
# and specify the fully qualified class name to the JavaScript interface
14-
# class:
15-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16-
# public *;
17-
#}
18-
19-
## Below are the suggested rules from the developer documentation:
20-
## https://developers.optimizely.com/x/solutions/sdks/reference/index.html?language=android&platform=mobile#installation
21-
22-
# Optimizely
23-
#-keep class com.optimizely.ab.** { *; }
24-
25-
# Gson
26-
#-keepnames class com.google.gson.Gson
27-
28-
# Safely ignore warnings about other libraries since we are using Gson
29-
#-dontwarn com.fasterxml.jackson.**
10+
# when gson is replaced with jackson-databind json parser
3011
-keep class com.fasterxml.jackson.** {*;}
31-
-dontwarn com.google.gson.**
32-
-dontwarn com.optimizely.ab.config.parser.**
33-
#-dontwarn org.json.**
34-
35-
# Annotations
36-
#-dontwarn javax.annotation.**
37-
38-
# Findbugs
39-
#-dontwarn edu.umd.cs.findbugs.annotations.SuppressFBWarnings
40-
41-
# slf4j
42-
#-dontwarn org.slf4j.**
43-
#-keep class org.slf4j.** {*;}
4412

45-
# Android Logger
46-
#-keep class com.noveogroup.android.log.** { *; }
13+
#-printconfiguration proguard-merged-config.txt

user-profile/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ android {
2828
versionCode 1
2929
versionName version_name
3030
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
31-
consumerProguardFiles '../proguard-rules.txt'
3231
}
3332
testOptions {
3433
unitTests.returnDefaultValues = true
3534
}
3635
buildTypes {
3736
release {
3837
minifyEnabled false
39-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4038
}
4139
debug {
4240
testCoverageEnabled true

user-profile/proguard-rules.pro

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)