-
Notifications
You must be signed in to change notification settings - Fork 671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coil 3.0.0 R8 missing classes detected #2637
Comments
+1. Additionally, I also get this:
So I don't think Per the docs, my application class is like so: @HiltAndroidApp
MyApplication: Application(), Configuration.Provider, SingletonImageLoader.Factory {
…
@OptIn(ExperimentalCoilApi::class)
override fun newImageLoader(context: PlatformContext) = ImageLoader.Builder(context)
.components {
add(OkHttpNetworkFetcherFactory(cacheStrategy = { CacheControlCacheStrategy() }))
}.build()
} |
@adhirajsinghchauhan You are right. After adding
Forgot to meantion that we also have this code in our Application class: @HiltAndroidApp
class MyApp : Application(), SingletonImageLoader.Factory, Configuration.Provider {
…
@OptIn(ExperimentalCoilApi::class)
override fun newImageLoader(context: PlatformContext): ImageLoader {
return ImageLoader.Builder(this)
.components {
add(OkHttpNetworkFetcherFactory(cacheStrategy = { CacheControlCacheStrategy() }))
add(SvgDecoder.Factory())
add(VideoFrameDecoder.Factory())
}
.logger(
object : Logger {
override var minLevel: Level = Level.Verbose
override fun log(
tag: String,
level: Level,
message: String?,
throwable: Throwable?
) {
logVerbose("COIL") { message.toString() }
}
}
)
.build()
} |
Hmm we had another report of R8 issues here, but I haven't been able to repro it locally. Missing Do you use any special R8 config or hardcoded R8 version? As a work-around you could try:
|
@adhirajsinghchauhan Inspecting the JAR indicates |
I'm also having issues with the
The |
Same issue, images are not loading in debug build and debug logger saying
Removing the custom fetcher factory resolves the issue, without following block it loads images properly
|
Be wary though, as this is must be provided if your use-case requires respecting I imagine anything that relies on |
I tried this, but it didn't work. |
Ofcourse, postponing migration to 3.0.0 for now as I require |
Does anyone have a way to reproduce this issue locally? Referencing |
I've created a repository with detailed commits, for my issue with the debug build. Haven't tried a release build: https://github.com/JanMalch/coil3bug As @lmiskovic mentioned, it only occurs after adding a connectivityChecker = { ctx -> ConnectivityChecker(ctx) } It seems that even an explicit |
@JanMalch Thanks for the repro project! I'm able to reproduce the error locally. It seems like there's some kind issue with the code generated for this function specifically: fun OkHttpNetworkFetcherFactory(
callFactory: () -> Call.Factory = ::OkHttpClient,
cacheStrategy: () -> CacheStrategy = { CacheStrategy.DEFAULT },
connectivityChecker: (PlatformContext) -> ConnectivityChecker = ::ConnectivityChecker,
) Hopefully we can work around the generated code issue. For now folks can use your work around. |
This is working. But we still get the R8 error for release builds:
When I build with |
@colinrtwhite I switched to add(OkHttpNetworkFetcherFactory(cacheStrategy = { CacheControlCacheStrategy() })) The release builds does not show any R8 errors anymore and images are loading (so no runtime errors). Looks like your changes fixed the issue! 🎊 |
Awesome, thanks for checking! Will ship this in |
@colinrtwhite Without the workaround we're still getting this issue with 3.0.4 🤔 add(OkHttpNetworkFetcherFactory( { OkHttpClient.Builder().build() })) |
@ychescale9 Ah yep there was another report of this on ASG as well unfortunately. They were able to work around the issue by inlining the add(
Fetcher.Factory<Uri> { data, options, imageLoader ->
if (data.scheme == "http" || data.scheme == "https") {
NetworkFetcher(
url = data.toString(),
options = options,
networkClient = networkClient,
diskCache = lazy { imageLoader.diskCache },
cacheStrategy = CacheStrategy.DEFAULT,
connectivityChecker = ConnectivityChecker.ONLINE,
)
} else {
null
}
}
) |
Im having the R8 issue using the 3.0.4. Im using a default implementation with just these 3 ## Coil
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil"}
coil-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil"}
coil-svg = { module = "io.coil-kt.coil3:coil-svg", version.ref = "coil"} |
Does it worth to reopen this issue? |
@MessiasLima Let's reopen to track, but we need a way to reproduce this issue to fix it. The issue is solved for the previous project here. |
I don't know if the below is directly related to Coil 3 (3.0.4) is currently using Java's ServiceLoader (you can see ServiceLoaderComponentRegistry here) in order to make it easier for developers to not have to add the fetchers and decoders manually by default. It seems ServiceLoader relies on the presence of a META-INF/services folder (which Coil 3 has added for each dependency). Because of the qualified class name requirement (package name + class name), it is very probable that the classes extending either FetcherServiceLoaderTarget or DecoderServiceLoaderTarget must be kept by ProGuard/R8 (maybe -keepnames), and I have not seen proguard rules being included with the dependencies. The class OkHttpNetworkFetcherServiceLoaderTarget implements FetcherServiceLoaderTarget. Also to note that the META-INF folder should not be excluded it seems (which was the case for me), as it was a popular solution to do with |
@AlfredAndroidTedmob R8 has a built in optimization that automatically rewrites the service loader implementation to call the class directly. Info about it is linked from the service loader JVM implementation. As a result Coil does not need to ship extra R8 rules in its artifact. To be clear, you do not need to add For |
@colinrtwhite Thank you for the clarification. All my projects still use Coil (not Coil 3) as of now in production builds that are obfuscated, and I did not have time to properly migrate any of them yet and test. I think the PlatformContext R8 warning from ConnectivityChecker could be from the aggressive R8 mode? |
@AlfredAndroidTedmob I don't think this is related to R8 full mode. The sample project in this repo uses R8 full mode, but I'm not able reproduce the exception after updating the I'm hoping Kotlin 2.1 might fix this issue. @yschimke if you use the latest snapshot (which builds with Kotlin 2.1) does it fix the issue? |
@colinrtwhite did you mean to tag me? |
@yschimke Sorry! Meant to tag @ychescale9. |
@colinrtwhite Just tested with |
Hello, I am a beginner in KMP. I heard that coil can display images across platforms, but I have encountered the same problem. It runs well in Android, iOS, and Desktop-jvm (Debug), but Desktop-jvm (Release) cannot display images.
When I try to set it will display normally. I guess it's caused by R8, but my app doesn't have a proguard file configured. As a beginner, I don't know how to configure it. Then, I provide the error message for the onError that cannot display images in the release version: 2024.12.19 I found a way to set up the proguard file. I only need |
@masterQian These rules will keep the fetcher and decoder service loaders if they're being stripped: -keep class * extends coil3.util.DecoderServiceLoaderTarget { *; }
-keep class * extends coil3.util.FetcherServiceLoaderTarget { *; } Alternatively you can disable the service loader with Ideally these rules shouldn't be required as it's expected that R8 will rewrite the service loader to directly instantiate the class and avoid the service loader penalty. If you have a sample that reproduces this please post it here or file a bug with the R8 component in the Android issue tracker. |
Describe the bug
After switching to Coil 3.0.0 the R8 task fails with the following error:
The
missing_rules.txt.
contains-dontwarn coil3.PlatformContext
. So maybe this should just be shipped as a consumer R8/ProGuard rule?To Reproduce
Migrate to Coil 3.0, try to build minified Android app.
Version
Coil 3.0.0, AGP 8.7.2
The text was updated successfully, but these errors were encountered: