I’m trying to use KMP with Apollo and an existing ...
# multiplatform
w
I’m trying to use KMP with Apollo and an existing schema. I’ve got things setup on the gradle side, but when I try to build with my schema and a basic query I get:
Could not initialize class com.apollographql.apollo.compiler.parser.Schema
Anyone run into something similar before?
m
At first glance it looks like conflicting dependencies in the buildscript classpath. Can you post the build results with
--stacktrace
?
My guess is that it fails on
Copy code
private val UTF8_BOM = "EFBBBF".decodeHex()
That's most likely because you have an older okio version in your
buildSrc
classpath
w
m
Can you update okio in your buildSrc to
2.5.0
?
If okio is included transitively, you might have to add it
w
Added it, same stacktrace.
m
bummer
Can you add the whole apollo-gradle-plugin in buildSrc maybe ?
I'm pretty sure it comes from this: https://github.com/gradle/gradle/issues/4741
Basically dependencies in buildSrc override the ones in other parts of your build scripts and might cause runtime crashes like this
Something else you can try to debug is run
./gradlew buildEnvironment
. That'll should tell you waht
okio
and
apollo-compiler
dependencies are used
w
Interesting. I’m not seeing apollo show up at all. And okio is at
1.16.0
m
I'm not seeing apollo
You might have to run it in your module:
./gradlew :$module:buildEnvironment
w
Thanks.
apollo-compiler:2.0.2
and
okio:2.5.0
m
That sounds appropriate
I was really suspecting the
decodeHex
method which is a recent addition of okio
w
I’m not sure if this helps, but when I ran the build again with a stacktrace, I got
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.apollographql.apollo.compiler.parser.Schema
m
If you have
build.gradle.kts
files, can you try adding something like this at the root of the script ?
Copy code
println("test".decodeHex().toString())
In the same build.gradle.kts file where you apply the apollo plugin ? To make sure okio dependency is working well ?
w
Disregard that snippet. I pasted the wrong one.
m
Whatt is different from the first one ?
w
I think I just missed the first line. It looked off, but it’s hard to read snippets on slack.
m
it is !
Last resort solution: you can run your build with
-Dorg.gradle.debug=true
and set breakpoints in intelliJ to have more details where the crash happens
w
Dumb question: do I just drop that
println
anywhere in the root of
build.gradle.kts
?
m
yup
That should fail during configuration so before your actual crash (that happens at execution)
w
Yup. That does fail in my build.
m
Something like a missing
ByteString.Companion
class ?
w
Ohh, sorry, I put the okio in the wrong
build.gradle.kts
That fixed that build issue.
m
👍
This gradle "feature/bug" is really annoying
w
Still getting build errors, but the model generation seems to have worked.
Thank you for the help!
👍 1
m
Ahah good luck, see you in another thread, maybe !
w
🙇