No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier when using htmlunit in Android Studio Project
Asked Answered
P

2

9

I am using htmlunit 2.36.0 in my Android Studio Project. I successfully compiled the apk but I am getting some runtime errors when I try to get a webpage. Before, I was getting the following error:

java.lang.BootstrapMethodError: Exception from call site

But I was able to fix the issue by adding this in the gradle:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

However, now I am facing another error:

 java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar!classes3.dex)
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:151)
        at com.gargoylesoftware.htmlunit.httpclient.HtmlUnitSSLConnectionSocketFactory.buildSSLSocketFactory(HtmlUnitSSLConnectionSocketFactory.java:89)
        at com.gargoylesoftware.htmlunit.HttpWebConnection.configureHttpsScheme(HttpWebConnection.java:635)
        at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClientBuilder(HttpWebConnection.java:558)
        at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClientBuilder(HttpWebConnection.java:519)
        at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:171)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1407)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1326)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:396)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:317)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:469)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:450)

Apparently, there is no static field instance of AllowAllHostnameVerifier in its own class or or its superclasses. I have no idea how to fix this.

Porcine answered 26/2, 2020 at 22:1 Comment(0)
R
0

As hc.apache.org documented:

AllowAllHostnameVerifier Deprecated. (4.4) Use NoopHostnameVerifier

If you downgrade dependencies's version to 4.3(2013~2015) exception will be resolved.

implementation 'net.sourceforge.htmlunit:htmlunit:2.15'
Radiation answered 28/2, 2020 at 12:37 Comment(4)
@DeborahAnn The main problem is htmlunit. htmlunit 2.36.0 removed AllowAllHostnameVerifierRadiation
@DeborahAnn you can not use htmlunit 2.36.0 for lower versions of httpclientRadiation
Can we talk in chat?Porcine
By the way, it works only with implementation 'net.sourceforge.htmlunit:htmlunit:2.14'. No need for the httpcomponents. I forgot to ask you something. Have you had the chance to try other versions below 2.36.0? Is 2.14 the only one to circumvent the issue?Porcine
L
1

Use the port for android:

https://github.com/HtmlUnit/htmlunit-android

Use this as the dependency:

implementation("net.sourceforge.htmlunit:htmlunit-android:2.63.0")
Loran answered 4/8, 2022 at 13:0 Comment(0)
R
0

As hc.apache.org documented:

AllowAllHostnameVerifier Deprecated. (4.4) Use NoopHostnameVerifier

If you downgrade dependencies's version to 4.3(2013~2015) exception will be resolved.

implementation 'net.sourceforge.htmlunit:htmlunit:2.15'
Radiation answered 28/2, 2020 at 12:37 Comment(4)
@DeborahAnn The main problem is htmlunit. htmlunit 2.36.0 removed AllowAllHostnameVerifierRadiation
@DeborahAnn you can not use htmlunit 2.36.0 for lower versions of httpclientRadiation
Can we talk in chat?Porcine
By the way, it works only with implementation 'net.sourceforge.htmlunit:htmlunit:2.14'. No need for the httpcomponents. I forgot to ask you something. Have you had the chance to try other versions below 2.36.0? Is 2.14 the only one to circumvent the issue?Porcine

© 2022 - 2024 — McMap. All rights reserved.