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

Android 7 and lower compatibility problem #2000

Closed
gregko opened this issue Sep 19, 2023 · 7 comments
Closed

Android 7 and lower compatibility problem #2000

gregko opened this issue Sep 19, 2023 · 7 comments

Comments

@gregko
Copy link

gregko commented Sep 19, 2023

StringUtil.java in line 338 has this code:

private static final ThreadLocal<Stack<StringBuilder>> threadLocalBuilders = ThreadLocal.withInitial(Stack::new);

However on Android 7 and lower (or maybe 6 and lower) the method ThreadLocal.withInitial() is not available, and the users of my Android app with older devices experience a crash. For now I replaced it with:

private static final ThreadLocal<Stack<StringBuilder>> threadLocalBuilders = new ThreadLocal<Stack<StringBuilder>>() {
        @Override
        protected Stack<StringBuilder> initialValue() {
            return new Stack<StringBuilder>();
        }
    };

Hopefully this or similar work-around could be incorporated into the official version of JSOUP... Thanks!

Greg

@jhy
Copy link
Owner

jhy commented Sep 20, 2023

Hi Greg - can you please see this note from the readme:

Android support
When used in Android projects, core library desugaring with the NIO specification should be enabled to support Java 8+ features.

Enabling that configuration should fix the issue. Could you please test and confirm?

@Isira-Seneviratne FYI

@Isira-Seneviratne
Copy link
Contributor

This issue was fixed a while back; it requires core library desugaring to work on Android versions below 8.

@gregko
Copy link
Author

gregko commented Sep 20, 2023

Thank you for the kind answer. Guess it is an alternative, although for now it seems an overkill for my app to pull a lot more code and components necessary for desugaring for the sake of one line of code. I'll consider this in the future, if necessary, for now will just use my own slightly modified build of jsoup. An awesome product, by the way. I did support it financially in the past, but years ago, maybe it's time to express my gratitude again in that way.

Greg

@Isira-Seneviratne
Copy link
Contributor

There's a minimal configuration available, maybe you could give that a try: https://developer.android.com/studio/write/java11-minimal-support-table

@gregko
Copy link
Author

gregko commented Sep 20, 2023

Thank you again. I confirm that desugaring fixes this problem, although adds over 200 kB to my app's APK size. It's probably safer to use it for the future changes in jsoup or other libraries.

@jhy
Copy link
Owner

jhy commented Oct 18, 2023

Thanks @Isira-Seneviratne and @gregko for resolving the issue.

BTW:

An awesome product, by the way. I did support it financially in the past,

Thanks for your feedback, much appreciated! But just for the record -- so far I have not / jsoup has not solicited or received any donations. I'm hoping this is just a mistaken memory :) and not an unscrupulous site that pretends to accept donations on behalf of open source work. Please ping me directly (jonathan@hedley.net) if we should dive deeper into this.

@jhy jhy closed this as completed Oct 18, 2023
@gregko
Copy link
Author

gregko commented Oct 18, 2023

I'm sorry, most probably mistaken memory. The project in which I use jsoup goes on since 2012 (although I'm not sure at which point I started using jsoup in it), and I tried to support many of open source projects that I use there. I apologize again.

Greg

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

3 participants