Skip to content

FAQ

Have a question that isn't part of the FAQ? Check StackOverflow with the tag #coil or search Github discussions.

Can Coil be used with Java projects or mixed Kotlin/Java projects?

Yes! Read here.

How do I preload an image?

Launch an image request with no target:

val request = ImageRequest.Builder(context)
    .data("https://example.com/image.jpg")
    .build()
imageLoader.enqueue(request)

That will preload the image and save it to the disk and memory caches.

If you only want to preload to the disk cache you can skip decoding and saving to the memory cache like so:

val request = ImageRequest.Builder(context)
    .data("https://example.com/image.jpg")
    // Disables writing to the memory cache.
    .memoryCachePolicy(CachePolicy.DISABLED)
    // Skips the decode step so we don't waste time/memory decoding the image into memory.
    .decoderFactory(BlackholeDecoder.Factory())
    .build()
imageLoader.enqueue(request)

How do I enable logging?

Set logger(DebugLogger()) when constructing your ImageLoader.

Note

DebugLogger should only be used in debug builds.

How do I target Java 8 or Java 11?

Coil requires Java 8 bytecode. This is enabled by default on the Android Gradle Plugin 4.2.0 and later and the Kotlin Gradle Plugin 1.5.0 and later. If you're using older versions of those plugins add the following to your Gradle build script:

android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

As of Coil 3.2.0, Java 11 bytecode is required for coil-compose and coil-compose-core:

android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = "11"
    }
}

Why do I get a Skiko version warning with Compose Multiplatform?

Compose Multiplatform will print a warning like this if Coil's Skiko dependency is older than Compose Multiplatform's:

w: Skiko dependencies' versions are incompatible.

Skiko does not guarantee binary compatibility between milestone versions because it wraps Skia, whose milestone versions can introduce breaking changes. This warning should not be assumed safe to ignore. Coil releases track Compose Multiplatform stable releases and their Skiko versions, so if you encounter this warning, first update Coil to the latest version.

NOTE: Coil doesn't release new versions only to match the Skiko versions used by alpha and beta Compose Multiplatform releases. However, if there is a binary compatibility issue that requires Coil to depend on a newer Skiko version, Coil will publish an alpha release with the updated dependency.

If you've updated Coil to the latest version and the warning is still present you can suppress the warning like so:

Compose Multiplatform >= 1.13.0

Add the following to the build.gradle.kts file of each module that applies the Compose Multiplatform plugin:

compose {
    dependencyCompatibility {
        exclude("io.coil-kt.coil3")
    }
}

This disables the compatibility check only for Coil.

Older Compose Multiplatform versions:

Add the following to your gradle.properties file:

org.jetbrains.compose.library.compatibility.check.disable=true

This disables all Compose Multiplatform library compatibility checks for all libraries, including Coil.

How do I get development snapshots?

Add the snapshots repository to your list of repositories:

Gradle (.gradle):

allprojects {
    repositories {
        maven { url 'https://central.sonatype.com/repository/maven-snapshots/' }
    }
}

Gradle Kotlin DSL (.gradle.kts):

allprojects {
    repositories {
        maven("https://central.sonatype.com/repository/maven-snapshots/")
    }
}

Then depend on the same artifacts with the latest snapshot version.

Note

Snapshots are deployed for each new commit on main that passes CI. They can potentially contain breaking changes or may be unstable. Use at your own risk.

How to I use Proguard with Coil?

To use Proguard with Coil, add these Proguard rules to your config.

You may also need to add custom rules for Ktor, OkHttp, and Coroutines.

Note

You do not need to add any custom rules for Coil if you use R8, which is the default code shrinker on Android. The rules are added automatically.