https://kotlinlang.org logo
#android
Title
# android
v

vivekneel

06/20/2017, 5:55 AM
Anyone was successfully able to use dagger in project which uses both java and kotlin? I'm not able to inject in kotlin classes
r

radityagumay

06/20/2017, 6:25 AM
vivekneel: kindly post error log
r

rcgroot

06/20/2017, 7:57 AM
I managed, running with all the stable versions.
v

vivekneel

06/20/2017, 9:12 AM
@radityagumay My bad, Just figured it out that I forgot to remove
apply plugin: 'com.neenbedankt.android-apt
Now it’s working fine. Thanks guys.
r

radityagumay

06/20/2017, 9:52 AM
Good. If you use AS 3 Canary 4 you should not use apt or kapt again
👍 1
w

waqas

06/20/2017, 10:08 AM
So that means it should work without
apt libraries.daggerCompiler
?
@radityagumay I removed the apt and kapt both. I am using Kotlin only in tests for now. I changed every compile to implementation and provided to compileOnly etc. But Dagger related classes are not generated in tests though. In normal java code Dagger generated classes are available. Any idea what I need to do more to have my previous setup back? I have this as annotation processor now:
testAnnotationProcessor libraries.daggerCompiler
annotationProcessor libraries.daggerCompiler
Kotlin version is
1.1.2-5
dagger and dagger compiler version is
2.10
.
r

radityagumay

06/20/2017, 1:35 PM
Have you clean and rebuild? Sound weird, that should work.
w

waqas

06/20/2017, 1:37 PM
@radityagumay I was able to fix this by updating the kotlin plugin again from plugins menu
r

radityagumay

06/20/2017, 1:38 PM
Well done. Great!
w

waqas

06/20/2017, 1:38 PM
On rechecking again even though it was installed android studio shows the current version to 4 again 🤔 , trying it one more time..
r

radityagumay

06/20/2017, 1:42 PM
If you can't, I think this bug from AS 3 Canary 4. 😂
😞 1
Did you put code somewhere for dagger compiler?
So I can check it
w

waqas

06/20/2017, 1:46 PM
@radityagumay this is the gist of important parts. Also I shouldn't need a separate testAnnotationProcessor as this used to be kaptAndroidTest before but now same processor should work 🤔 ? https://pastebin.com/M6CJdHtn
Copy code
0.31 KB
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
 
 
 
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    implementation libraries.dagger
    compileOnly libraries.appcompat
    annotationProcessor libraries.daggerCompiler
    testAnnotationProcessor libraries.daggerCompiler
}
BTW I am using
org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-5
v

vivekneel

06/20/2017, 2:17 PM
Have you also added generateStub?
@waqas ^
w

waqas

06/20/2017, 2:18 PM
@vivekneel No I had it before, but after removing kapt I removed that too.
@vivekneel do I need to add it?
v

vivekneel

06/20/2017, 2:23 PM
Dagger classes are generated after adding stub. Try adding and see in your /app/build.gradle
w

waqas

06/20/2017, 2:27 PM
But as both apt/kpat are removed in new implementation, how it's recognized? I get this
Error:(35, 0) Could not set unknown property 'generateStubs' for object of type com.android.build.gradle.LibraryExtension.
v

vivekneel

06/20/2017, 2:29 PM
Pls post your build.gradle
w

waqas

06/20/2017, 2:35 PM
v

vivekneel

06/20/2017, 2:45 PM
@waqas try adding
Copy code
kapt {
        generateStubs = true
    }
under android {}
w

waqas

06/20/2017, 2:46 PM
okay..
@vivekneel nope, still no dagger classes in test sources