Integrating Fresco Image Loading Library with RePlugin in Android
This guide explains what Fresco is, shows how to add its dependencies, use SimpleDraweeView in XML, and details a plugin‑friendly approach for sharing Fresco across host and RePlugin modules by converting the drawee AAR to a JAR and handling custom attribute callbacks.
1. Fresco Introduction
Fresco is an open‑source image loading framework from Facebook. It handles image fetching, caching and display, allowing developers to avoid writing their own loading logic.
2. Simple Usage
Fresco provides the SimpleDraweeView widget, which shows a placeholder while the image loads, automatically replaces it with the target image, and releases memory when the view leaves the screen.
2.1 Add Dependency
2.2 Initialize
2.3 Use in XML Layout
2.4 Load Image
3. Using Fresco When the App Is Plugin‑Based
3.1 Host and Plugin Share Fresco
Because Fresco includes UI components and custom attributes, it cannot be simply compiled as a logic‑only library. Both host and plugins can include Fresco, but that leads to duplicate code and larger APKs.
The solution is to let the host compile Fresco, while plugins declare it as provided (or compileOnly in newer Gradle). This way the plugin does not bundle Fresco code.
At runtime, RePlugin’s setUseHostClassIfNotFound() makes the plugin fall back to the host’s class loader when a class is missing.
3.2 Modifying Fresco Source
The drawee module is packaged as an AAR because it defines custom attributes in attrs.xml. To make it a JAR, remove attrs.xml and replace the attribute references with a custom callback interface.
After deleting attrs.xml and adding the interface, the drawee module builds as a JAR, and the plugin implements the interface to supply the needed attributes.
3.3 Using Fresco in a Plugin
The plugin must:
Declare provided dependency on the modified drawee.jar and its dependencies.
Copy the original attrs.xml from the AAR into the plugin’s res/values directory.
Implement the custom attribute callback interface, read the attributes via reflection, and set the implementation for the drawee module.
With these changes, the plugin can reuse the host’s Fresco library without bundling duplicate code.
All source code referenced in this article is available at https://github.com/Qihoo360/RePlugin/tree/dev/replugin-sample-extra.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Qizhuo Club
360 Mobile tech channel sharing practical experience and original insights from 360 Mobile Security and other teams across Android, iOS, big data, AI, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
