Skip to content

Java Compatibility

Coil's API was designed to be Kotlin-first. It leverages Kotlin language features such as inlined lambdas, receiver params, default arguments, and extension functions, which are not available in Java.

Also, suspend functions cannot be implemented in Java. This means custom Transformations, Size Resolvers, Fetchers, and Decoders must be implemented in Kotlin.

With these limitations in mind, here is the recommended way to execute load requests from Java:

LoadRequest request = ImageLoaders.newLoadBuilder(imageLoader, context)

If you're using the default ImageLoader, you can get it via Coil.loader().


You should not use the API extension functions in Java. Instead, you should create Request objects manually like above.

suspend functions cannot be easily called from Java. Thus, to get an image synchronously you'll have to create a wrapper function for get:

object ImageLoaderCompat {
    fun getBlocking(
        imageLoader: ImageLoader,
        request: GetRequest
    ): Drawable = runBlocking { imageLoader.get(request) }

Then call the ImageLoaderCompat function from Java:

GetRequest request = ImageLoaders.newGetBuilder(imageLoader)
        .size(1080, 1920)
Drawable drawable = ImageLoaderCompat.getBlocking(imageLoader, request);


ImageLoaderCompat.getBlocking will block the current thread instead of suspending. Do not call this from the main thread.