https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
w

wingchi

05/07/2020, 8:36 PM
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

mbonnin

05/07/2020, 10:30 PM
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

wingchi

05/07/2020, 10:33 PM
m

mbonnin

05/07/2020, 10:34 PM
Can you update okio in your buildSrc to
2.5.0
?
If okio is included transitively, you might have to add it
w

wingchi

05/07/2020, 10:44 PM
Added it, same stacktrace.
m

mbonnin

05/07/2020, 10:47 PM
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

wingchi

05/07/2020, 10:55 PM
Interesting. I’m not seeing apollo show up at all. And okio is at
1.16.0
m

mbonnin

05/07/2020, 10:57 PM
I'm not seeing apollo
You might have to run it in your module:
./gradlew :$module:buildEnvironment
w

wingchi

05/07/2020, 11:01 PM
Thanks.
apollo-compiler:2.0.2
and
okio:2.5.0
m

mbonnin

05/07/2020, 11:02 PM
That sounds appropriate
I was really suspecting the
decodeHex
method which is a recent addition of okio
w

wingchi

05/07/2020, 11:03 PM
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

mbonnin

05/07/2020, 11:07 PM
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

wingchi

05/07/2020, 11:07 PM
Disregard that snippet. I pasted the wrong one.
m

mbonnin

05/07/2020, 11:10 PM
Whatt is different from the first one ?
w

wingchi

05/07/2020, 11:11 PM
I think I just missed the first line. It looked off, but it’s hard to read snippets on slack.
m

mbonnin

05/07/2020, 11:11 PM
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

wingchi

05/07/2020, 11:13 PM
Dumb question: do I just drop that
println
anywhere in the root of
build.gradle.kts
?
m

mbonnin

05/07/2020, 11:13 PM
yup
That should fail during configuration so before your actual crash (that happens at execution)
w

wingchi

05/07/2020, 11:15 PM
Yup. That does fail in my build.
m

mbonnin

05/07/2020, 11:16 PM
Something like a missing
ByteString.Companion
class ?
w

wingchi

05/07/2020, 11:18 PM
Ohh, sorry, I put the okio in the wrong
build.gradle.kts
That fixed that build issue.
m

mbonnin

05/07/2020, 11:19 PM
👍
This gradle "feature/bug" is really annoying
w

wingchi

05/07/2020, 11:20 PM
Still getting build errors, but the model generation seems to have worked.
Thank you for the help!
👍 1
m

mbonnin

05/07/2020, 11:20 PM
Ahah good luck, see you in another thread, maybe !
w

wingchi

05/07/2020, 11:20 PM
🙇
12 Views