9

In my application i want use Room library for use database, and for finally for generate APK i enable minify option (proguard) in Build.Gradle .

I use below version of Room library :

implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"

I write below codes in proguard-rules :

-dontwarn class android.arch.persistence.room.paging.LimitOffsetDataSource
-dontwarn interface android.arch.persistence.room.paging.LimitOffsetDataSource
-dontwarn class android.arch.util.paging.CountedDataSource
-dontwarn interface android.arch.util.paging.CountedDataSource

But when generate APK show me below error in Build tab :

Unknown option 'android.arch.persistence.room.paging.LimitOffsetDataSource' in line 39 of file '/Volumes/M/Test Projects/MyApp/app/proguard-rules.pro'

Show me error for this line :

-dontwarn class android.arch.persistence.room.paging.LimitOffsetDataSource

How can fix this issue?

Dr. Jake
  • 249
  • 2
  • 3
  • 9

3 Answers3

17

If you use androidx

-keep class * extends androidx.room.RoomDatabase
-keep @androidx.room.Entity class *
-dontwarn androidx.room.paging.**
User Rebo
  • 3,056
  • 25
  • 30
2

Add below lines for keep section in your proguard file.

-dontwarn android.arch.util.paging.CountedDataSource
-dontwarn android.arch.persistence.room.paging.LimitOffsetDataSource
karan
  • 8,637
  • 3
  • 41
  • 78
  • thanks this fixed, but again show me this error : `Expecting java type before ';' in line 71 of file '/Volumes/M/Test Projects/MyApp/app/proguard-rules.pro'` for this line : `-keepclasseswithmembers class * {native ;}` . how can i fix it too? please help me – Dr. Jake Dec 10 '18 at 06:57
  • use `native ;` you need to add tag `` – karan Dec 10 '18 at 07:01
1

You need to add this line in the proguard file

-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}

And your model entity should look like this add SerializedName("key")

@Entity
data class ListElement(

@NonNull
@PrimaryKey
@SerializedName("id")
@Expose
val id: Int,

@SerializedName("userId")
@Expose
val userId: Int,

@SerializedName("title")
@Expose
val title: String,

@SerializedName("completed")
@Expose
val completed: Boolean

)

Shogun Nassar
  • 606
  • 7
  • 16