prof18 / RSS-Parser

A Kotlin Multiplatform library to parse a RSS Feed
Apache License 2.0
499 stars 127 forks source link

Parser crashes on API<21 with HTTPS: "java.net.SocketTimeoutException [...] (port 443)" #54

Closed yattoz closed 4 years ago

yattoz commented 4 years ago

EDIT: see post below for better specif for the error. This was not the real problem, but was caught by the try...catch block. On API 20 and down, the parser does not parse anything. I get at runtime with a try...catch block

I/dalvikvm: Could not find method java.time.Duration.toMillis, referenced from method okhttp3.OkHttpClient$Builder.readTimeout
W/dalvikvm: VFY: unable to resolve virtual method 42983: Ljava/time/Duration;.toMillis ()J

I compile with Java 8 support, which is, to the best of my knowledge, the recommended version for Android development. I would like to target API 16+. I am using Kotlin. In my build.gradle there is:

    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }

It's odd that no error is raised on API21+. I assume it is because of the transition to Android Runtime (ART) instead of the Dalvik VM. I am a bit surprised since I saw on your Readme that your library was compliant with API15+.

Where did things go wrong? Should I use a newer version of Java? (is it even possible for Android?). Is your library actually limited to API21+?

Thank you very much.

yattoz commented 4 years ago

Correction: after removing the try...catch block, I get the following crash : java.net.SocketTimeoutException: failed to connect to tsumugi.forum-thalie.fr/2001:41d0:2:f15a:: (port 443) after 10000ms The URL I'd like to parse is : "https://tsumugi.forum-thalie.fr/?feed=rss2" This website forces HTTPS connection, so there's no plain HTTP connection available. (And, between us, plain HTTP shouldn't be used in 2019 anyway). Still, it is worth noticing that whenever I try an URL with plain HTTP connection, it does work on API20 and down. For example : http://www.clubic.com/articles.rss

prof18 commented 4 years ago

I think that the issue is related to TLS. Try with this solution: https://stackoverflow.com/a/53590809/5264056

yattoz commented 4 years ago

I didn't manage to make it work. Furthermore the articles I read about enabling TLS1.2 on legacy devices needs Google Play Services (which is a requirement some people don't want to have), and even on some devices it doesn't work as expected. So this solution does not suit me. On my side, I can simply redirect legacy devices to the webpage or using a WebView and keep the RSS view for API21+. That's how I went. I think that it would be nice to warn your users by writing something in your README about TLS1.2 support on API19-, so that users can get informed about this limitation from Android. In any case, thank you very much for your support, I hope this won't block many users.

prof18 commented 4 years ago

Thank you for the suggestion, I'll try to improve the README.