在我的应用程序中,我希望使用Room库来使用数据库,最后,对于generate APK,我在Build.Gradle中启用minify选项(proguard)。
我使用的是房间库的以下版本: :
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"我用保护规则写了下面的代码:
-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但是当生成APK时,在Build 选项卡中显示错误:
Unknown option 'android.arch.persistence.room.paging.LimitOffsetDataSource' in line 39 of file '/Volumes/M/Test Projects/MyApp/app/proguard-rules.pro'显示这一行的错误:
-dontwarn class android.arch.persistence.room.paging.LimitOffsetDataSource如何解决这个问题?
发布于 2018-12-10 06:55:55
在程序保护文件中为keep部分添加下面的行。
-dontwarn android.arch.util.paging.CountedDataSource
-dontwarn android.arch.persistence.room.paging.LimitOffsetDataSource发布于 2019-10-23 18:29:38
如果你用雄激素
-keep class * extends androidx.room.RoomDatabase
-keep @androidx.room.Entity class *
-dontwarn androidx.room.paging.**发布于 2021-10-07 06:04:50
您需要将这一行添加到pro卫士文件中。
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}模型实体应该如下所示: 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)
https://stackoverflow.com/questions/53700773
复制相似问题