rssreader icon indicating copy to clipboard operation
rssreader copied to clipboard

Freeze on Android Device

Open kevlahnota opened this issue 1 year ago • 4 comments

I assume there are classes that needs to be retained on Proguard.cfg hence the freeze issue (are there any information so It works on android). Tested using Android 14 (SDK 34) compiled using Java 17 and rssreader v3.6.0 (the build tools complains using java 21 so I use lower version). The java file is this:

import com.apptasticsoftware.rssreader.Item;
import com.apptasticsoftware.rssreader.RssReader;
import org.apache.commons.text.StringEscapeUtils;

import java.io.InputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;

public class RSS {
    private static RssReader reader;
    private static RssReader getReader() {
        if (reader == null)
            reader = new RssReader();
        return reader;
    }

    public static String getLog(Date buildDateOriginal, SimpleDateFormat DateFor, Date max) {
        String message = "";
        try {
            URL url = new URL("https://github.com/Card-Forge/forge/commits/master.atom");
            InputStream inputStream = url.openStream();
            List<Item> items = getReader().read(inputStream).toList();
            StringBuilder logs = new StringBuilder();
            int c = 0;
            for (Item i : items) {
                if (i.getTitle().isEmpty())
                    continue;
                String title = TextUtil.stripNonValidXMLCharacters(i.getTitle().get());
                if (title.contains("Merge"))
                    continue;
                ZonedDateTime zonedDateTime = i.getPubDateZonedDateTime().isPresent() ? i.getPubDateZonedDateTime().get() : null;
                if (zonedDateTime == null)
                    continue;
                Date feedDate = Date.from(zonedDateTime.toInstant());
                if (buildDateOriginal != null && feedDate.before(buildDateOriginal))
                    continue;
                if (max != null && feedDate.after(max))
                    continue;
                logs.append(DateFor.format(feedDate)).append(" | ").append(StringEscapeUtils.unescapeXml(title).replace("\n", "").replace("        ", "")).append("\n\n");
                if (c >= 15)
                    break;
                c++;
            }
            if (logs.length() > 0)
                message += ("\n\nLatest Changes:\n\n" + logs);
            inputStream.close();
        } catch (Exception e) {
            //e.printStackTrace();
        }
        return message;
    }
}

It works fine on desktop version though.

kevlahnota avatar Oct 08 '24 01:10 kevlahnota

The RssReader library relies on classes not supported in the Android platform.

XML Parsing: It uses javax.xml.stream.XMLStreamReader (StAX API), which is not directly available on Android. But an Android compatible StAX implementation like Woodstox can be used.

HTTP Requests: It uses java.net.http.HttpClient, which is also not available on Android. It can be replaced with a 3rd-party HTTP client library designed for Android (e.g., OkHttp).

w3stling avatar Oct 13 '24 08:10 w3stling

The RssReader library relies on classes not supported in the Android platform.

XML Parsing: It uses javax.xml.stream.XMLStreamReader (StAX API), which is not directly available on Android. But an Android compatible StAX implementation like Woodstox can be used.

HTTP Requests: It uses java.net.http.HttpClient, which is also not available on Android. It can be replaced with a 3rd-party HTTP client library designed for Android (e.g., OkHttp).

Thanks for pointing it out, gonna try if importing those dependency will work.

kevlahnota avatar Oct 13 '24 22:10 kevlahnota

I got it working on Android. It's a temporary solution that doesn't require any code changes to the library. I will improve Android support in a future version.

Add dependencies:

implementation 'com.fasterxml.woodstox:woodstox-core:7.0.0'
implementation 'com.apptasticsoftware:rssreader:3.8.2'

Create class java.net.http.HttpClient

package java.net.http;

public class HttpClient {
}

Provide an instance of HttpClient when creating a new RssReader object.

URL url = new URL("https://github.com/Card-Forge/forge/commits/master.atom");
InputStream inputStream = url.openStream();
List<Item> items = new RssReader(new HttpClient()).read(inputStream).toList()

This solution is limited to reading a feed from an input stream.

w3stling avatar Oct 22 '24 19:10 w3stling

Ok thanks, gonna try that on the project.

kevlahnota avatar Oct 22 '24 20:10 kevlahnota

Hello, just wanted to share that providing an empty HttpClient does work. Also wanted to note that the ItunesRssReader currently doesn't accept HttpClient in its constructor so we can only use RssReader in Android. Any estimates on the timeline for Android support?

jiebo avatar Dec 02 '24 06:12 jiebo

just wanted to share that providing an empty HttpClient does work.

Is it a problem during build-time or run-time? Do you receive any error messages?

w3stling avatar Dec 02 '24 17:12 w3stling

just wanted to share that providing an empty HttpClient does work.

Is it a problem during build-time or run-time? Do you receive any error messages?

Hi Peter, nope there wasn't a problem, it worked well for me. Added a comment because I noted that OP hadn't provided a follow-up, hence I thought it sensible to provide an update that your proposed solution worked as intended.

jiebo avatar Dec 02 '24 18:12 jiebo

I misread your first comment. Perfect, thanks @jiebo for the update.

Also wanted to note that the ItunesRssReader currently doesn't accept HttpClient in its constructor so we can only use RssReader in Android.

Well spotted I will fix this.

Any estimates on the timeline for Android support?

I don't have an estimate. Use the workaround for now.

A small breaking API change is necessary to add Android support. I need time to ensure a smooth implementation with minimal impact on existing users.

w3stling avatar Dec 02 '24 19:12 w3stling

Closing issue.

See workaround for Android: https://github.com/w3stling/rssreader/issues/189#issuecomment-2430089416

w3stling avatar Dec 02 '24 20:12 w3stling