rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.73k stars 1.21k forks source link

Runtime error: java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier #1012

Open he1ex-tG opened 2 years ago

he1ex-tG commented 2 years ago

I am using Android Studio 4.1.3, and I am writing project in Kotlin according to this instruction https://github.com/rubenlagus/TelegramBots/wiki/Getting-Started

But I get the runtime 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!classes4.dex)

How can I resolve this issue?

Velosh commented 2 years ago

This library wasn't built for Android

Velosh commented 2 years ago

You've to adapt, I guess.

he1ex-tG commented 2 years ago

This library wasn't built for Android

It looks like you are right. I tried to run the same code in Kontlin console application (win10) and it works good. I write Kotlin Andriod project and want to get notifications by Telegram. What options I have? Build http requiests?

Velosh commented 2 years ago

I think you should fork and use a library (Like: okhttp, retrofit) that specializes in HTTP request (and etc). And use that specialized library, adapt and replace the current one that doesn't exist on Android but that exists on Desktop. Got it?

Velosh commented 2 years ago

I always recommend doing it in an adapted way, but if you want something more agile: https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.3.4

That should works, add that on your project's build.gradle. (Not sure if that library is the correct one)

he1ex-tG commented 2 years ago

I always recommend doing it in an adapted way, but if you want something more agile: https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.3.4

That should works, add that on your project's build.gradle. (Not sure if that library is the correct one)

implementation ("org.apache.httpcomponents:httpclient:4.3.6") implementation ("org.telegram:telegrambots:5.5.0") { exclude group: 'org.apache.httpcomponents', module: 'httpclient' } Here I downgrade the module whit early version -> I am getting error message: Cannot resolve symbol 'NoopHostnameVerifier'. It's true. Metod NoopHostnameVerifier is used in bot code but httpclient version 4.3.6 did not have this.

he1ex-tG commented 2 years ago

I think you should fork and use a library (Like: okhttp, retrofit) that specializes in HTTP request (and etc). And use that specialized library, adapt and replace the current one that doesn't exist on Android but that exists on Desktop. Got it?

Yes, I got. But it too hard to my purposes )) I started using okhttp and already got positive results.

Thank you, bro!

Velosh commented 2 years ago

I always recommend doing it in an adapted way, but if you want something more agile: https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.3.4 That should works, add that on your project's build.gradle. (Not sure if that library is the correct one)

implementation ("org.apache.httpcomponents:httpclient:4.3.6") implementation ("org.telegram:telegrambots:5.5.0") { exclude group: 'org.apache.httpcomponents', module: 'httpclient' } Here I downgrade the module whit early version -> I am getting error message: Cannot resolve symbol 'NoopHostnameVerifier'. It's true. Metod NoopHostnameVerifier is used in bot code but httpclient version 4.3.6 did not have this.

Try with: implementation ("org.apache.httpcomponents:httpclient:4.5.13") implementation ("org.apache.httpcomponents:httpmime:4.5.13")

he1ex-tG commented 2 years ago

I always recommend doing it in an adapted way, but if you want something more agile: https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.3.4 That should works, add that on your project's build.gradle. (Not sure if that library is the correct one)

implementation ("org.apache.httpcomponents:httpclient:4.3.6") implementation ("org.telegram:telegrambots:5.5.0") { exclude group: 'org.apache.httpcomponents', module: 'httpclient' } Here I downgrade the module whit early version -> I am getting error message: Cannot resolve symbol 'NoopHostnameVerifier'. It's true. Metod NoopHostnameVerifier is used in bot code but httpclient version 4.3.6 did not have this.

Try with: implementation ("org.apache.httpcomponents:httpclient:4.5.13") implementation ("org.apache.httpcomponents:httpmime:4.5.13")

No effect. I got the same error.

rubenlagus commented 3 months ago

Although not officially supported, the library may work now properly on Android

NikoPera commented 5 days ago

Hi @rubenlagus, I'm trying to use the library on Android and I've seen all the messages here but no luck to make it work. I have the same problem of this issue..

I've just read your message "Although not officially supported, the library may work now properly on Android" how?