square / picasso

A powerful image downloading and caching library for Android
https://square.github.io/picasso/
Apache License 2.0
18.72k stars 3.97k forks source link

Using Picasso without Okhttp/Okio #2192

Open Alireza-Farahani opened 3 years ago

Alireza-Farahani commented 3 years ago

I'm working on an app with limitation of being offline (No internet permission in manifest) and small Apk size (2mb). I think Picasso should not be bound to online/remote images and it would be great if I can use Picasso for its caching and transformation pipeline and other features.

I tried to exclude Okhttp and Okio dependency from Picasso in Gradle, create a dummy Downloader and added Okio and Okhttp as compileOnly dependencies (Downloader is never used when using device resources), but it crashes in runtime on this lines from Utils.java class because ByteString belongs to Okio

private static final ByteString WEBP_FILE_HEADER_RIFF = ByteString.encodeUtf8("RIFF");
private static final ByteString WEBP_FILE_HEADER_WEBP = ByteString.encodeUtf8("WEBP");

Is it possible at all to use Picasso without Okio and Okhttp?

I know that you keep Github issues for bugs and feature request, but I thought this questions is too relevant to Picasso internals to be asked in Stackoverflow.

JakeWharton commented 3 years ago

You can use it without OkHttp. Okio is required.

Alireza-Farahani commented 3 years ago

Is my approach for excluding Okhttp OK or do you recommend anything else?

TacoTheDank commented 3 years ago

@JakeWharton What do you think about separating classes that use OkHttp into their own module? (Something like picasso-okhttp). Would that be possible?

JakeWharton commented 3 years ago

We can certainly consider making it easier to exclude OkHttp long-term (assuming Picasso will ever see another release), but it would likely always be an opt-out thing rather than requiring the overwhelming majority of users to opt-in to OkHttp.