https://kotlinlang.org logo
#kapt
Title
# kapt
e

Eugen Martynov

08/07/2019, 8:45 AM
Is there setup example how to build android app with annotation processing and kapt with JDK9+?
g

gildor

08/07/2019, 8:49 AM
kapt works with JDK9+
no special config required But particular APs may have own problems
e

Eugen Martynov

08/07/2019, 8:50 AM
I have problem with Generated class from JDK
g

gildor

08/07/2019, 8:50 AM
For example DataBinding do not work for us, even if you solve all problems with jaxb dependency
Dagger?
e

Eugen Martynov

08/07/2019, 8:50 AM
yes
ah, if databinding is still issue then I will not even try
g

gildor

08/07/2019, 8:50 AM
it’s kapt bug that doesn’t propagate target JVM version to annotation processor
I’m not 100% sure
but bindings just not generating
no other exceptions, just no output
e

Eugen Martynov

08/07/2019, 8:51 AM
I found next workaround
Copy code
if (project.hasProperty('kapt')) {
    // Reference for 'kapt' DSL: <https://kotlinlang.org/docs/reference/kapt.html#java-compiler-options>
    kapt {
      // we expect this closure to run over a org.jetbrains.kotlin.gradle.plugin.KaptExtension
      javacOptions {
        option('-source', '8')
        option('-target', '8')
      }
    }
  }
g

gildor

08/07/2019, 8:51 AM
yes, it doesn’t work for me for some reason
e

Eugen Martynov

08/07/2019, 8:52 AM
same
oke, thank you!
g

gildor

08/07/2019, 8:52 AM
So I use com.github.pengrad:jdk9-deps
this is just a dependency with Generated annotation
so it solves problem for me, but again, looks that binding do not work for some reason
e

Eugen Martynov

08/07/2019, 8:53 AM
oke, let me check google state about jdk9 and databinding
g

gildor

08/07/2019, 9:16 AM
Could you try to build you project with fixed dagger
e

Eugen Martynov

08/07/2019, 9:25 AM
I will try today after lunch
I will keep you updated
g

gildor

08/07/2019, 9:27 AM
Thanks
s

Sergey Chelombitko

08/07/2019, 11:17 AM
-source 8
works well in kotlin-android modules but broken in pure kotlin modules https://youtrack.jetbrains.com/issue/KT-33028
g

gildor

08/07/2019, 11:47 AM
@Sergey Chelombitko Thanks!
e

Eugen Martynov

08/08/2019, 6:45 AM
@gildor After just adding your suggested dependency I have
Copy code
java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
g

gildor

08/08/2019, 6:45 AM
Yes, it’s from bindings
Try to add Jaxb dependencies to kapt classpath:
Copy code
kapt "javax.xml.bind:jaxb-api:2.3.1"
kapt "com.sun.xml.bind:jaxb-core:2.3.0.1"
kapt "com.sun.xml.bind:jaxb-impl:2.3.2"
for some reason I also had this problem until I add the same to
annotationProcessor
classpath, but not sure why,
e

Eugen Martynov

08/08/2019, 6:46 AM
I should check databinding sources
probably why use it for xml parsing or whatever
g

gildor

08/08/2019, 6:47 AM
Yes. of course
Anyway, because Jaxb removed from JVM default classes you have to add it
Could you please try? Also add this:
Copy code
annotationProcessor "javax.xml.bind:jaxb-api:2.3.1"
annotationProcessor "com.sun.xml.bind:jaxb-core:2.3.0.1"
annotationProcessor "com.sun.xml.bind:jaxb-impl:2.3.2"
I’m not sure is it required or not, but looks like that even tho we don’t use Java APT directly, I would expect that Kapt should populate it for APT, but I don’t have any real information is it correct or not, I just tried to make it work
e

Eugen Martynov

08/08/2019, 6:55 AM
It is required if you still have somewhere java class with databinding
g

gildor

08/08/2019, 6:57 AM
Yes, but I would expect that Kapt sets own classpath to APT
e

Eugen Martynov

08/08/2019, 6:59 AM
oke
I ’m on the final stages
compileDebugJavaWithJavac
fails with the same class missing
g

gildor

08/08/2019, 7:01 AM
even with annotationProcessor?
e

Eugen Martynov

08/08/2019, 7:01 AM
it fixes
I added it to the gradle file that is applied for all subprojects
but looks like app is not in this set
final strokes
it is green
let see if everything is correctly generated/working
I see data binding generated classes
g

gildor

08/08/2019, 7:06 AM
Nice
e

Eugen Martynov

08/08/2019, 7:07 AM
The apk file looks correct. Installing…
It runs
Thank you!!!
g

gildor

08/08/2019, 7:08 AM
👍
Will try later too. We just recently updated on AGP 3.5, maybe something fixed
e

Eugen Martynov

08/08/2019, 9:35 AM
I’m actually trying this on AGP 3.5
g

gildor

08/08/2019, 9:38 AM
Yes, I got it, I tried on 3.4 as I remember
👍 1
10 Views