Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set proguard rule for Room library on Android

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?

like image 786
Dr. Jake Avatar asked Dec 10 '18 06:12

Dr. Jake


2 Answers

If you use androidx

-keep class * extends androidx.room.RoomDatabase
-keep @androidx.room.Entity class *
-dontwarn androidx.room.paging.**
like image 166
Виталий Робиновский Avatar answered Sep 28 '22 18:09

Виталий Робиновский


Add below lines for keep section in your proguard file.

-dontwarn android.arch.util.paging.CountedDataSource
-dontwarn android.arch.persistence.room.paging.LimitOffsetDataSource
like image 44
karan Avatar answered Sep 28 '22 17:09

karan