Coil is another open source image loading library on Android. Although there are already some very mature and excellent ones on Android such as Picasso, Glide, and Fresco, Coil’s main feature is that it incorporates some of the most popular technologies and trends in Android development. Using Kotlin as the development language and using coroutines, OKHttp, OKIO and AndroidX as first-class citizens, we hope to create a more light, modern image loading library. Specifically, it includes the following aspects:

  • Take advantage of Kotlin’s language features to create simple and elegant apis using extension functions, inline, lambda arguments, and sealed classes.
  • The Kotlin coroutine takes advantage of powerful cancelling non-blocking asynchronous programming and thread maximization features.
  • Use modern dependency libraries: OKHttp and OKIO are the de facto “standard” libraries for most apps today, and their powerful features enable Coil to avoid redeploying disk caching and buffering streams. Similarly, AndroidX-Lifecycle is officially recommended, and Coil is currently the only image-loading library supported for it.
  • Light weight: Coil’s code is almost one-eighth that of Glide’s, and much smaller than Fresco’s. And adds only about 1500 methods to APK (for apps that already rely on OKHttp and coroutines), comparable to Picasso and significantly less than Glide and Fresco.
  • Support extendedThe image-pipline of: Coil is mainly composed ofMappers , Fetchers, andDecodersMade up of three classes, you can easily customize: extending or overwriting the default behavior, or adding support for new file types.
  • Test friendliness: Coil’s basic service class isClassLoader, it is an interface, you can easily write the corresponding implementation class to test; And Coil provides both singletons and non-singletons to support DEPENDENCY injection.
  • No annotation processing: Annotation processing generally slows compilation, and Coil is avoided through the Kotlin extension function.

Coil currently supports all of the features found in other image-loading libraries, but it also has a unique feature: Dynamic image sampling, in short, when only one low-quality image can be cached in memory and a high-quality image needs to be displayed, Coil can initially hold lower-quality images as the ImageView placeHolder while loading the corresponding higher-quality images from the disk cache and then replace them in a “progressive” manner and eventually display them in the view, such as the most common scene from image list to preview large images. The above is the general introduction of Coil at present. The following is a brief introduction to the APPLICATION of the API of Coil.

API preview


// Load a basic URL (using the extension function, no intrusion on target)
imageView.load("https://www.website.com/image.jpg")

// Coil supports loading urls, uris, resources, drawables, bitmaps, files, etc
imageView.load(R.drawable.image)
imageView.load(File("/path/to/image.jpg"))
imageView.load(Uri.parse("content://com.android.externalstorage/image.jpg"))

// Requests configuration items can be implemented with the load lambda argument
imageView.load("https://www.website.com/image.jpg") {
    crossfade(true)
    placeholder(R.drawable.image)
    transformations(CircleCropTransformation())
}

// Customize targets, which contains the start, success and failure callbacks
Coil.load(context, "https://www.website.com/image.jpg") {
    target { drawable ->
        // Handle the successful result.}}// Get the picture object directly by using the suspend function get
val drawable = Coil.get("https://www.website.com/image.jpg")
Copy the code

The warehouse address

To learn more, go to Coil’s GitHub address: github.com/coil-kt/coi…