hi guys. What would be the proper way to shade the...
# getting-started
a
hi guys. What would be the proper way to shade the
kotlin-stdlib
. I have to do this as one of the dependency of my project brings older version of kotlin and I face issues at runtime. I tried using the standard
johnrengelman
gradle plugin to shade the library and it worked well. The problem is, it converts kotlin code to java code in the shaded library. I loose all suspend functions in the shaded file and stuck at it. How can I deal with it? Thanks in advance 🙂
h
What do you mean with converting? This is very strange. It shouldn`t and doesn’t convert any code.
a
what I mean by example:
runBlocking
in normal file looks like this:
Copy code
@Throws(InterruptedException::class)
public actual fun <T> runBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T {
// some code
}
the same
runBlocking
from the shaded file:
Copy code
public static final <T> T runBlocking(@NotNull CoroutineContext context, @NotNull Function2<? super CoroutineScope, ? super Continuation<? super T>, ? extends Object> block) throws InterruptedException {
        return BuildersKt__BuildersKt.runBlocking(context, block);
    }
Thanks for the help @hfhbd 🙂
e
This has nothing to do with converting. The bytecode is simply not being recognized as Kotlin/suspending when the metadata is renamed by the shading. It still works the same.
note that if you shade
kotlin-stdlib
, even if you adjust the rules to not touch metadata (I don't know if it's possible with shadow, I know it is with r8), your suspend funs will not work with external Kotlin callers. why do you even want to do this?
The shadow plugin is problematic in Kotlin code generally, since it will rename what it thinks are package references, including literal strings
"kotlin"
in your code, breaking it
a
Thanks for the thorough response @ephemient. Will look back at my usecase and see if I can avoid shading. Or will ask for more help with more details if I can't 🙂