Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR in Android - NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier #444

Closed
p4ulor opened this issue Feb 15, 2022 · 19 comments

Comments

@p4ulor
Copy link

p4ulor commented Feb 15, 2022

Hi. Im sorry, but I've been trying to solve this problem for a while now and I really need help because this is frying by brain and eyes. So I would love to have some help.

The error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: paulor.nutritiontrackerkotlin, PID: 25944
    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!classes2.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:670)
        at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClientBuilder(HttpWebConnection.java:588)
        at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClientBuilder(HttpWebConnection.java:544)
        at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:173)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1597)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1519)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:498)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:413)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:551)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:533)
        at paulor.nutritiontrackerkotlin.MainActivityViewModel.getFood(MainActivity.kt:97)
        at paulor.nutritiontrackerkotlin.fragments.HomeFragment.onCreateView$lambda-0(HomeFragment.kt:26)
        at paulor.nutritiontrackerkotlin.fragments.HomeFragment.$r8$lambda$oLhVoC0TON1oPmPiWZ-31sqsrqE(Unknown Source:0)
        at paulor.nutritiontrackerkotlin.fragments.HomeFragment$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
        at android.view.View.performClick(View.java:6294)
        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1131)
        at android.view.View$PerformClick.run(View.java:24770)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
        ```
@dshetyo
Copy link

dshetyo commented Feb 18, 2022

I am also facing this same issue when using on Andorid. I know that the root cause of this is AllowAllHostnameVerifier Deprecated. (4.4) on Andorid api level 23+. See https://stackoverflow.com/questions/60423257/no-static-field-instance-of-type-lorg-apache-http-conn-ssl-allowallhostnameverif

But what is the solution?

@rbri
Copy link
Member

rbri commented Feb 18, 2022

I tried to solve this by 'shading' please try to use

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit-android</artifactId>
    <version>2.56.0-SNAPSHOT</version>
</dependency>

instead of the htmlunit dependency. You have to add the snapshot repo also

<snapshotRepository>
    <id>sonatype-nexus-snapshots</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>

Please report your findings, i really like to get this working on Android and i will support you. But i have not time to set up an android dev at the moment.

If it works i will update and release the project.

@p4ulor
Copy link
Author

p4ulor commented Feb 18, 2022

It gave me:

Could not find net.sourceforge.htmlunit:htmlunit-android:2.56.0-snapshot.

I searched this around, this person also had the same problem
And I also tried his second attempt here and also didnt work

Is that package public? I didn't find it on the internet

@rbri
Copy link
Member

rbri commented Feb 18, 2022

Please try 2.56.0-SNAPSHOT

@rbri
Copy link
Member

rbri commented Feb 18, 2022

Do you use gradle?

@p4ulor
Copy link
Author

p4ulor commented Feb 18, 2022

I also tried capslock
image

Yes I'm using gradle. here is the line

@rbri
Copy link
Member

rbri commented Feb 18, 2022

you have to add the snapshot repo and i just made a fix. Please use 2.58.0-SNAPSHOT

@p4ulor
Copy link
Author

p4ulor commented Feb 18, 2022

So, the good news is that it runs. Thank you and good work (even though I'm a newbie and don't know what or how you did it lol)

The bad news is that now I'm having this error that sometimes happens on the website, even in normal browsers:
image

The error 503 first byte timeout

here is my code (im trying diferent options and stuff):

WebClient(BrowserVersion.CHROME).use { webClient ->
        //webClient.options.isThrowExceptionOnScriptError = false
        webClient.options.isCssEnabled = true
        webClient.options.isUseInsecureSSL = true
        webClient.options.isJavaScriptEnabled = true
        webClient.waitForBackgroundJavaScript(10000)
        log("We runnin'")
        val page = webClient.getPage<HtmlPage>("https://nutritiondata.self.com/facts/nut-and-seed-products/3086/2")
        Thread.sleep(11_000)
        log(page.asXml())
        val div = page.getHtmlElementById<HtmlDivision>("nf1 left")
        log(div.toString())
        val pageAsText = page.asNormalizedText()
        log(pageAsText)
        log("I waited")
        }

And to put it simple for others like me:
I had to put the line maven { url "https://oss.sonatype.org/content/repositories/snapshots"} in the settings.gradle file, here:

     dependencyResolutionManagement {
   repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
   repositories {
       google()
       maven { url "https://oss.sonatype.org/content/repositories/snapshots"}
       mavenCentral()
       jcenter() // Warning: this repository is going to shut down soon
   }
}

p4ulor added a commit to p4ulor/NutritionTrackerApp that referenced this issue Feb 18, 2022
HtmlUnit/htmlunit#444
htmlunit returning lil html page with "error 503 first byte timeout"

web scrapping bee also not working giving out :
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!classes2.dex)

now im gonna play league of legends or mortal shell, tired of this
@dshetyo
Copy link

dshetyo commented Feb 19, 2022

I tested the original issue and I can confirm thats its resolved. The issue @p4ulor is facing is unrelated to htmlUnit lib. The website he is trying to hit is too slow.

I am simly trying to load google.com and am getting error.

My code


WebClient webClient = new WebClient(BrowserVersion.CHROME);

        try {
            Log.d(HTML_TAG, "Loading page");
            webClient.getOptions().setJavaScriptEnabled(true);
            webClient.getOptions().setCssEnabled(true);
            webClient.waitForBackgroundJavaScript(20*1000);
            final HtmlPage page = webClient.getPage("https://google.com");
     }


@rocess: com.mindedges.whatsapptracker, PID: 15821
    java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/datatransfer/ClipboardOwner;
        at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.handleCharacters(HtmlUnitNekoDOMBuilder.java:593)
        at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:521)
        at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source:35)
        at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:511)
        at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1247)
        at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1172)
        at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:219)
        at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:312)
        at net.sourceforge.htmlunit.cyberneko.HTMLScanner$SpecialScanner.scan(HTMLScanner.java:3314)
        at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:937)
        at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:443)
        at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:394)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source:5)
        at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.parse(HtmlUnitNekoDOMBuilder.java:758)
        at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser.parse(HtmlUnitNekoHtmlParser.java:204)
        at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:298)
        at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:218)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:686)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:588)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:506)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:413)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:551)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:533)
        at java.lang.Thread.run(Thread.java:923)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.datatransfer.ClipboardOwner" on path: DexPathList

Tried some other website and agin getting error.


2022-02-18 17:36:42.943 15961-16024/com.mindedges.whatsapptracker E/JavaScriptErrorListener: Error during JavaScript execution
    ======= EXCEPTION START ========
    EcmaError: lineNumber=[1] column=[0] lineSource=[<no source>] name=[ReferenceError] sourceName=[https://web.whatsapp.com/libsignal-protocol-d27cee2.min.js] message=[ReferenceError: "WebAssembly" is not defined. (https://web.whatsapp.com/libsignal-protocol-d27cee2.min.js#1)]
    com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "WebAssembly" is not defined. (https://web.whatsapp.com/libsignal-protocol-d27cee2.min.js#1)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:956)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:582)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:481)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:349)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:834)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:810)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:112)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1037)
        at com.gargoylesoftware.htmlunit.html.ScriptElementSupport.executeScriptIfNeeded(ScriptElementSupport.java:196)
        at com.gargoylesoftware.htmlunit.html.ScriptElementSupport$1.execute(ScriptElementSupport.java:120)
        at com.gargoylesoftware.htmlunit.html.ScriptElementSupport.onAllChildrenAddedToPage(ScriptElementSupport.java:143)
        at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:191)
        at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:559)
        at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source:35)
        at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:511)
        at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1247)
        at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1172)
        at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:219)
        at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:312)
        at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3189)
        at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2114)
        at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:937)
        at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:443)
        at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:394)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source:5)
        at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.parse(HtmlUnitNekoDOMBuilder.java:758)
        at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser.parse(HtmlUnitNekoHtmlParser.java:204)
        at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:298)
        at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:218)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:686)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:588)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:506)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:413)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:551)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:533)
        at com.mindedges.whatsapptracker.FirstFragment.testHtmlUnit(FirstFragment.java:74)
        at com.mindedges.whatsapptracker.FirstFragment.access$000(FirstFragment.java:27)
2022-02-18 17:36:42.943 15961-16024/com.mindedges.whatsapptracker E/JavaScriptErrorListener:     at com.mindedges.whatsapptracker.FirstFragment$1.run(FirstFragment.java:48)
        at java.lang.Thread.run(Thread.java:923)
     Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: ReferenceError: "WebAssembly" is not defined. (https://web.whatsapp.com/libsignal-protocol-d27cee2.min.js#1)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4610)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4591)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:4679)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:2024)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.name(ScriptRuntime.java:1962)
        at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1977)
        at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1053)
        at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:92)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:389)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:335)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3913)
        at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:105)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:825)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:939)
        	... 38 more
    Enclosed exception: 
    net.sourceforge.htmlunit.corejs.javascript.EcmaError: ReferenceError: "WebAssembly" is not defined. (https://web.whatsapp.com/libsignal-protocol-d27cee2.min.js#1)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4610)
        at net.


@rbri
Copy link
Member

rbri commented Feb 19, 2022

@dshetyo the last one is a different story (and fixable :-))
Please open a new issue for this.

@christian-draeger
Copy link

FYI: i just switched to htmlunit-android:2.58.0-SNAPSHOT over here

at least all my server side tests are still passing after switching everything from htmlunit to htmlunit-android which leads me to the question if there is any problem to always use htmlunit-android (android as well as any other java runtime on a server or local machine)? @rbri why you differenciate and made an special android release instead of fixing it as part of the general html-unit release? just that i can better understand the decision here :)

furthermore i release a snapshot version of my changes at skrape{it} that as said now has htmlunit-android:2.58.0-SNAPSHOT as transitive dependency.

i will play around with an android build using this snaopshot version after lunch

@p4ulor if you want to you could also try if the snapshot release is doing its job and we thereby fixed your issue here:
skrapeit/skrape.it#180

here is documented how to use the snapshot release: https://github.com/skrapeit/skrape.it#add-experimental-stuff

@rbri
Copy link
Member

rbri commented Feb 19, 2022

Technically there is no difference and you can stay with the android version - it is exactly the same code as the 'real' htmlunit. But there is some flexibility you are loosing because the httpclient is (shaded) included in your jar file and no longer an separate jar. This might be a problem for some users.

Will close this issue for now and update the readme a bit.

If you like you can have a look at the htmlunit-android readme and report open questions or suggestions.

@rbri rbri closed this as completed Feb 19, 2022
@christian-draeger
Copy link

christian-draeger commented Feb 22, 2022

ok, thx for clarification.
i opened a follow-up at htmlunit-android repo
HtmlUnit/htmlunit-android#1

@dshetyo
Copy link

dshetyo commented Feb 22, 2022

I opened a issue #448

@Cyberavater
Copy link

Hello, I'm getting this on 2.63.0

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!classes4.dex)
                                                                                                    	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:151)

@rbri
Copy link
Member

rbri commented Aug 4, 2022

@rbri
Copy link
Member

rbri commented Aug 4, 2022

@black-snow as you already have updated the readme - maybe you can place a link to the android project also.

@Cyberavater
Copy link

Yes, it works nicely now, thanks!

@black-snow
Copy link
Contributor

sure thing, PR incoming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants