在android项目中使用htmlunit.jar库时的Proguard问题

时间:2018-04-25 05:48:01

标签: java android android-gradle htmlunit android-proguard

我在我的android项目中使用了htmlunit-2.15.jar。当我尝试创建一个签名的apk时,它会抛出一些proguard错误

Caused by: java.io.IOException: java.lang.IllegalArgumentException: Can't find common super class of [com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLScriptable] (with 2 known super classes) and [java/lang/Class] (with 2 known super classes)
at com.android.build.gradle.internal.transforms.ProGuardTransform.doMinification(ProGuardTransform.java:259)

Caused by: java.lang.IllegalArgumentException: Can't find common super class of [com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLScriptable] (with 2 known super classes) and [java/lang/Class] (with 2 known super classes) at proguard.evaluation.value.TypedReferenceValue.findCommonClass(TypedReferenceValue.java:450)

所以,请你帮我修复这个问题,因为我的项目正在进行中,我需要立即修复和重新构建。在android studio中从gradle 2.3.3 迁移到 3.0.1 时progaurd中的问题。

我在proguard-rules.pro

中添加了这两行
-dontwarn com.gargoylesoftware.htmlunit.**
-keep class com.gargoylesoftware.htmlunit.** { *; }

-dontwarn netscape.javascript.**
-keep class netscape.javascript.** { *; }

1 个答案:

答案 0 :(得分:1)

感谢我对解决方案进行了排序并进行了修复,我才添加了库

implementation 'net.sourceforge.htmlunit:htmlunit-core-js:2.5'

在应用程序build.gradle文件中

此库在htmlunit.jar中具有所有缺少的类。 并且在我的 progaurd文件中添加了这3行。

-keep class com.gargoylesoftware.htmlunit.html.DomNode { *; }
-keep class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable { *; }
-keep class net.sourceforge.htmlunit.corejs.javascript.** { *; }

-keep class com.gargoylesoftware.htmlunit.html.DomNode { *; } -keep class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable { *; } -keep class net.sourceforge.htmlunit.corejs.javascript.** { *; }

以上更改解决了我的问题,现在我可以生成签名的apk文件