如何在 Android 上为 Room 库设置 proguard 规则 [英] How to set proguard rule for Room library on Android

查看:33
本文介绍了如何在 Android 上为 Room 库设置 proguard 规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想使用 Room 库来使用 database,最后为了 generate APK 我启用 minifyBuild.Gradle 中的 strong> 选项(proguard).

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 .

我使用以下版本的 Room 库:

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

我在 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

但是当生成 APK 时在 Build 选项卡中显示以下错误:

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'

显示这一行的错误:

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

如何解决这个问题?

推荐答案

在 proguard 文件中为 keep 部分添加以下行.

Add below lines for keep section in your proguard file.

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

这篇关于如何在 Android 上为 Room 库设置 proguard 规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆