英文:
proguard rule not working for some Java files
问题
我正在使用 Room 数据库库,接口中有以下方法:
@Query("SELECT * FROM employee WHERE deptName = :DeptName")
List<Employee> getAllEmployeeFrom(String deptName);
我已经应用了 Proguard 规则:
-keep interface androidx.* { *; }
-keepclasseswithmembernames public interface packagename.dao.*{*;}
-keepclasseswithmembernames public class packagename.dao.*$DefaultImpls{*;}
但是在 Proguard 混淆之后生成的最终类是:
@Query("SELECT * FROM employee WHERE deptName = :DeptName")
List getAllEmployeeFrom(String deptName);
这里缺少 List<TYPE>
。请帮助我理解为什么 List 类型被改变了。同样的代码在 Kotlin 中编写可以正常工作。我不能将 Java 文件迁移到 Kotlin。这些 Proguard 规则必须为 Java 文件编写。
英文:
I am using room database library and interface has method
@Query(Select * from employee where deptName = :DeptName)
List<Employee> getAllEmployeeFrom(deptName: String);
I have applied proguard rule:
-keep interface androidx.* { *; }
-keepclasseswithmembernames public interface packagename.dao.*{*;}
-keepclasseswithmembernames public class packagename.dao.*$DefaultImpls{*;}
But final class generated after proguard obfuscation is
@Query(Select * from employee where deptName = :DeptName)
List getAllEmployeeFrom(deptName: String);
Here the List<TYPE> is missing. Please help me to understand why List type is changed. Also the same code written in Kotlin works fine. I cannot migrate Java file to Kotlin. The proguard rule has to be written for java files.
答案1
得分: 0
-keep选项指定了需要保留的应用程序入口点。
-keep class packageName.Employee ** { *; }
-keepclassmembers class packageName.Employee ** { *; }
英文:
> The -keep option specifies the entry point of the application that has
> to be preserved.
-keep class packageName.Employee ** { *; }
-keepclassmembers class packageName.Employee ** { *; }
答案2
得分: 0
你必须使用 -keepattributes Signature 以保留列表中的泛型。
根据 Proguard 文档 (https://www.guardsquare.com/manual/configuration/examples#library)
> 需要 "Signature" 属性才能访问泛型类型。
英文:
You must use -keepattributes Signature in order to keep the generic in the list.
According to Proguard documentation (https://www.guardsquare.com/manual/configuration/examples#library)
> The "Signature" attribute is required to be able to access generic types.
专注分享java语言的经验与见解,让所有开发者获益!
评论