Skip to content

Commit a0bf106

Browse files
fix: obfuscation fix
1 parent 795c43e commit a0bf106

File tree

2 files changed

+114
-6
lines changed

2 files changed

+114
-6
lines changed

app/proguard-rules.pro

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# removes such information by default, so configure it to keep all of it.
44
-keepattributes Signature
55

6+
# CRITICAL: Keep generic type information for TypeToken to work properly
7+
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
8+
-keepattributes *Annotation*
9+
610
# For using GSON @Expose annotation
711
-keepattributes *Annotation*
812

@@ -23,8 +27,74 @@
2327
}
2428

2529
# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
26-
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
27-
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
30+
# CRITICAL: Do NOT allow obfuscation or shrinking of TypeToken - it needs to preserve generic type information
31+
-keep class com.google.gson.reflect.TypeToken
32+
-keep class * extends com.google.gson.reflect.TypeToken
33+
34+
# Keep TypeToken constructors and methods to preserve generic type information
35+
-keepclassmembers class com.google.gson.reflect.TypeToken {
36+
<init>(...);
37+
<methods>;
38+
}
39+
40+
# Keep all Gson reflection classes that handle generic types
41+
-keep class com.google.gson.reflect.** { *; }
42+
43+
# CRITICAL: Keep Google Guava TypeToken and TypeCapture classes (used by Gson)
44+
-keep class com.google.common.reflect.TypeToken { *; }
45+
-keep class com.google.common.reflect.TypeCapture { *; }
46+
-keep class com.google.common.reflect.TypeToken$* { *; }
47+
-keep class com.google.common.reflect.TypeCapture$* { *; }
48+
49+
# Keep all anonymous subclasses of TypeToken (created by object : TypeToken<T>() {})
50+
-keep class * extends com.google.common.reflect.TypeToken { *; }
51+
-keep class * extends com.google.gson.reflect.TypeToken { *; }
52+
53+
# Keep Gson TypeAdapter classes used by Room TypeConverters
54+
-keep class * extends com.google.gson.TypeAdapter
55+
-keep class * implements com.google.gson.TypeAdapterFactory
56+
57+
# Keep Room TypeConverters that use Gson (important for complex types like List<SectionScoreDb>)
58+
-keep @androidx.room.TypeConverter class * { *; }
59+
-keepclassmembers class * {
60+
@androidx.room.TypeConverter <methods>;
61+
}
62+
63+
# Keep generic type information for Room entities with complex types
64+
-keepclassmembers class org.openedx.**.data.model.room.** {
65+
<fields>;
66+
<init>(...);
67+
* mapToDomain();
68+
* mapToRoomEntity();
69+
* mapToEntity();
70+
}
71+
72+
# CRITICAL: Keep the CourseConverter and all its TypeToken usage
73+
-keep class org.openedx.course.data.storage.CourseConverter { *; }
74+
-keepclassmembers class org.openedx.course.data.storage.CourseConverter {
75+
<init>(...);
76+
<methods>;
77+
}
78+
79+
# Keep anonymous TypeToken subclasses created in CourseConverter
80+
-keep class org.openedx.course.data.storage.CourseConverter$* { *; }
81+
82+
# CRITICAL: Prevent obfuscation of CourseConverter methods that use TypeToken
83+
-keepclassmembers,allowobfuscation class org.openedx.course.data.storage.CourseConverter {
84+
@androidx.room.TypeConverter <methods>;
85+
}
86+
87+
# Keep all TypeConverter classes that use Gson
88+
-keep class org.openedx.discovery.data.converter.DiscoveryConverter { *; }
89+
90+
# Keep the specific TypeToken usage patterns in TypeConverters
91+
-keepclassmembers class org.openedx.**.data.storage.** {
92+
@androidx.room.TypeConverter <methods>;
93+
}
94+
95+
-keepclassmembers class org.openedx.**.data.converter.** {
96+
@androidx.room.TypeConverter <methods>;
97+
}
2898
##---------------End: proguard configuration for Gson ----------
2999

30100
-keepclassmembers class * extends java.lang.Enum {
@@ -33,6 +103,45 @@
33103
public static ** valueOf(java.lang.String);
34104
}
35105

106+
##---------------Begin: proguard configuration for Kotlin Coroutines ----------
107+
# Keep all coroutine-related classes and methods
108+
-keep class kotlinx.coroutines.** { *; }
109+
-keep class kotlin.coroutines.** { *; }
110+
-keep class kotlin.coroutines.intrinsics.** { *; }
111+
112+
# Keep suspend functions and coroutine builders
113+
-keepclassmembers class * {
114+
kotlin.coroutines.Continuation *(...);
115+
}
116+
117+
# Keep coroutine context and related classes
118+
-keep class kotlinx.coroutines.CoroutineContext$* { *; }
119+
120+
# Keep Flow and StateFlow classes
121+
-keep class kotlinx.coroutines.flow.** { *; }
122+
123+
# Keep coroutine dispatchers
124+
-keep class kotlinx.coroutines.Dispatchers { *; }
125+
-keep class kotlinx.coroutines.Dispatchers$* { *; }
126+
127+
# Keep coroutine scope and job classes
128+
-keep class kotlinx.coroutines.CoroutineScope { *; }
129+
-keep class kotlinx.coroutines.Job { *; }
130+
-keep class kotlinx.coroutines.Job$* { *; }
131+
132+
# Keep coroutine intrinsics that are causing the error
133+
-keep class kotlin.coroutines.intrinsics.IntrinsicsKt { *; }
134+
-keep class kotlin.coroutines.intrinsics.IntrinsicsKt$* { *; }
135+
136+
# Keep suspend function markers
137+
-keepclassmembers class * {
138+
@kotlin.coroutines.RestrictsSuspension <methods>;
139+
}
140+
141+
# Keep coroutine-related annotations
142+
-keep @kotlin.coroutines.RestrictsSuspension class * { *; }
143+
##---------------End: proguard configuration for Kotlin Coroutines ----------
144+
36145
-dontwarn org.bouncycastle.jsse.BCSSLParameters
37146
-dontwarn org.bouncycastle.jsse.BCSSLSocket
38147
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider

course/src/main/java/org/openedx/course/data/storage/CourseConverter.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import org.openedx.core.data.model.room.BlockDb
77
import org.openedx.core.data.model.room.GradingPolicyDb
88
import org.openedx.core.data.model.room.SectionScoreDb
99
import org.openedx.core.data.model.room.discovery.CourseDateBlockDb
10-
import org.openedx.foundation.extension.genericType
1110
import java.util.Date
1211

1312
class CourseConverter {
@@ -30,7 +29,7 @@ class CourseConverter {
3029

3130
@TypeConverter
3231
fun toListOfString(value: String): List<String> {
33-
val type = genericType<List<String>>()
32+
val type = object : TypeToken<List<String>>() {}.type
3433
return Gson().fromJson(value, type)
3534
}
3635

@@ -42,7 +41,7 @@ class CourseConverter {
4241

4342
@TypeConverter
4443
fun toListOfBlockDbEntity(value: String): List<BlockDb> {
45-
val type = genericType<List<BlockDb>>()
44+
val type = object : TypeToken<List<BlockDb>>() {}.type
4645
return Gson().fromJson(value, type)
4746
}
4847

@@ -54,7 +53,7 @@ class CourseConverter {
5453

5554
@TypeConverter
5655
fun toListOfCourseDateBlockDb(value: String): List<CourseDateBlockDb> {
57-
val type = genericType<List<CourseDateBlockDb>>()
56+
val type = object : TypeToken<List<CourseDateBlockDb>>() {}.type
5857
return Gson().fromJson(value, type)
5958
}
6059

0 commit comments

Comments
 (0)