https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
dagger
  • r

    rattleshirt

    06/04/2017, 7:27 AM
    @dawidhyzy Neither. It was what @christiangruber mentioned. There was a github issue as well with the same problem. Thanks both!
    d
    • 2
    • 1
  • t

    trevjones

    08/25/2017, 4:19 AM
    if you are using gradle make sure you are using kapt and not apt or annotationProcessor. and the obvious, did you put
    @Component
    on it?
    k
    • 2
    • 1
  • t

    trevjones

    08/25/2017, 1:54 PM
    you are in control of ViewHolder creation in your adapter so you should use constructor injection
    p
    • 2
    • 5
  • j

    juliocbcotta

    10/02/2017, 4:56 PM
    So has anyone created a custom scope while using dagger android components?
    ➕ 1
    b
    • 2
    • 1
  • d

    dave08

    01/31/2018, 3:45 AM
    Oops, you're right, thanks, I was running the build with intellij and it didn't give me dagger error that I was missing a
    @Provides
    , only when I ran in terminal, I saw it, now everything works! Your 'did you see `kaptGenerateStubs`' question made me look there ... 😊
    g
    • 2
    • 19
  • d

    dave08

    01/31/2018, 11:41 AM
    Thanks @gildor! Now I'm having another error:
    java.lang.NoClassDefFoundError: javax/inject/Provider
    , when running?
    g
    • 2
    • 6
  • d

    dave08

    01/31/2018, 1:42 PM
    Could I ask another question @gildor? Given:
    @Provides @Singleton fun provideOdooClient(xmlRpcCoroutineClient: XmlRpcCoroutineClient): OdooClient =
    			OdooClientImpl(
    					xmlRpcCoroutineClient,
    					System.getenv("ODOO_HOST"),
    					System.getenv("ODOO_PORT")?.toInt(),
    					System.getenv("ODOO_DB")
    			)
    
    	@Provides @Named("isOdooClientReady") fun provideOdooClientStatus(odooClient: OdooClient): Deferred<Boolean> =
    			odooClient.login(
    					System.getenv("ODOO_USER"),
    					System.getenv("ODOO_PASS")
    			)
    And (in main verticle):
    @Inject @Named("isOdooClientReady") lateinit var isOdooClientReady: Deferred<Boolean>
    Is there any reason I should be getting
    ModelComponent.java:10: error: kotlinx.coroutines.experimental.Deferred<java.lang.Boolean> cannot be provided without an @Provides- or @Produces-annotated method.
        public abstract void inject(@org.jetbrains.annotations.NotNull()
    ?
    g
    • 2
    • 5
  • h

    hmole

    06/08/2018, 10:13 AM
    How can I deal with generated code that refers to classes that do not exists after I switch branch in git besides manually running clean?
    r
    d
    • 3
    • 2
  • t

    tamas.barta

    07/03/2018, 7:54 AM
    Hi! Our team is having issues with
    kapt
    tasks running for long minutes. We only use
    kapt
    for Dagger. Is there any known issues, that I couldn't find with my hours of googling on the topic? We use parallel task execution for many modules (of an Android app), and the result is still 10 minutes, which is made up mostly from dexing and
    kapt
    . We tried upgrading every library including Dagger, and the issue persists. Do you have any suggestions?
    r
    a
    +2
    • 5
    • 11
  • c

    cvmocanu

    08/06/2018, 4:35 PM
    Hello! How are you guys setting up kotlin + dagger2? Is there a way to make IntelliJ automatically run kapt as part of building (Ctrl+F9)? I am trying to use Dagger 2 in a Kotlin / maven project Here is what I tried: (1) setup add dagger-compiler as a dependency. "Settings > Build, Execution, Deployment > Compiler > Annotation Processors" for my maven module has "Enable annotation processing" checked and "Obtain processors from project classpath" So I quickly realized that option (1) obviously won't work if I write my dagger components and modules in kotlin code. So I tried (2) setup the kotlin maven plugin to run kapt with dagger2:
    <plugin>
                    <artifactId>kotlin-maven-plugin</artifactId>
                    <groupId>org.jetbrains.kotlin</groupId>
    
                    <executions>
                        <execution>
                            <id>kapt</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>kapt</goal>
                            </goals>
                            <configuration>
                                <sourceDirs>
                                    <sourceDir>src/main/kotlin</sourceDir>
                                    <sourceDir>src/main/java</sourceDir>
                                </sourceDirs>
                                <annotationProcessorPaths>
                                    <!-- Specify your annotation processors here. -->
                                    <annotationProcessorPath>
                                        <groupId>com.google.dagger</groupId>
                                        <artifactId>dagger-compiler</artifactId>
                                        <version>2.16</version>
                                    </annotationProcessorPath>
                                </annotationProcessorPaths>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    This works from maven, but IntelliJ is completely clueless. By this, I mean that no additional files are generated in my target directory when I press Ctrl+F9 (or choose to rebuild the module). There is only a "classes" directory there. (3) as a quick test I also tried a small gradle project. The only way I could get it to work was to delegate compile to gradle (Settings > Build, Execution, Deployment > Build Tools > Gradle > Runner -> enable: "Delegate build/run actions to gradle") But this means it's gradle that compiles & runs kapt, not IntelliJ. So now I'm out of ideas. Is there a way to make IntelliJ automatically run kapt as part of building (Ctrl+F9)? Or is basically dagger 2 useless on a maven + Kotlin project? If I have to do "mvn clean package" every time I change a class, that makes dagger 2 useless for me (and for anyone that cares about development productivity). Also, if you use gradle + dagger 2 + kotlin and you delegate build/run actions to gradle, doesn't this make the whole compilation unbearably slow? Especially given the fact that apparently kapt cannot run in gradle incremental mode (https://youtrack.jetbrains.com/issue/KT-11978).
    c
    • 2
    • 3
  • t

    trevjones

    08/09/2018, 3:13 AM
    I ran into this a long while ago when I was in a mixed java/kotlin project and don't think kotlin's compiler will emit bytecode without at least the wildcard generic. you might need to do the module in java to work around it or more appropriate would probably be to modify all the injection sites to match what the kotlin module exposes. If you were a peer on my team I would say something like lets follow effective java and
    Don’t use raw types
    👍 1
    d
    • 2
    • 1
  • n

    neuber

    08/23/2018, 8:32 PM
    C:\neuber\adt-bundle-windows-x86_64-20140702\sdk\wHome\app\src\main\java\neuberfran\com\whome\core\dagger\AppInjector.kt: (10, 9): Unresolved reference: DaggerAppComponent
    k
    s
    b
    • 4
    • 6
  • s

    Slackbot

    08/24/2018, 3:30 AM
    This message was deleted.
    a
    t
    r
    • 4
    • 3
  • l

    locke

    10/12/2018, 1:59 PM
    So the Dagger implementation was in this code base before I got here (third day in the code base), and the app was building and deploying successfully. I added DataBinding to an
    Activity
    refactor, and now am running into these issues where the DataBinding is failing. After a lot of debugging, I discovered that if I remove:
    implementation 'com.google.dagger:dagger-android:$project.daggerVersion'
    it successfully builds the DataBinding components (while failing on the Android-Dagger specific ones, obviously.) It is worth noting that DataBinding builds fine with the standard Dagger 2 include
    implementation "com.google.dagger:dagger:$project.daggerVersion"
    , it is only the Android specific module that is failing me I'm not receiving large blocks of errors, but I appreciate that suggestion either way.
    g
    • 2
    • 1
  • h

    hmole

    10/22/2018, 12:33 PM
    Does anyone have a convinient way to disable code formatting only for debug build in android?
    g
    • 2
    • 1
  • s

    Sam

    10/25/2018, 6:50 PM
    Is there a preference between @Named qualifier or custom qualifiers when dealing with different dependencies of same type?
    g
    • 2
    • 6
  • s

    Sam

    10/26/2018, 12:26 AM
    I personally prefer custom qualifier to get autofill and avoid any string typo with @Named
    g
    y
    • 3
    • 3
  • d

    David

    10/27/2018, 6:59 PM
    Hey @Sam - nah. It's a proper "high end" optimisation even for those Java users. I looked it up a while back and end up just doing the older style for my Kotlin modules and moved on. Be good to know if I was wrong on this point though? I think our time would be better spent turning things lazy if they need be and obvs not doing anything slow in the provisioning blocks.
    s
    • 2
    • 18
  • h

    hmole

    10/28/2018, 3:52 PM
    Better way of handling direct bindings with kotlin is to just declare another abstract module which will hold only
    @Binds
    bindings and then just include it via
    submodules
    , so you don't have to do
    @JvmStatic
    nonsense.
    s
    • 2
    • 4
  • s

    Sam

    10/29/2018, 4:32 PM
    I'm running into a issue where Dagger multibinding into a map fails compilation when i use Class as a key but works fine with String as a key for the map. With Class key, Dagger claims "cannot be provided without an @Provides-annotated method". Any pointers?
    b
    • 2
    • 2
  • d

    darkmoon_uk

    10/30/2018, 8:48 PM
    If you use Dagger with Kotlin, please upvote the addition of 'Incremental Annotation Processing' to
    kapt
    , lack of which is currently preventing Kotlin projects benefiting from the latest incremental features in both Gradle and Dagger2: https://youtrack.jetbrains.com/issue/KT-23880
    ➕ 1
    s
    • 2
    • 2
  • s

    Sangeet

    10/31/2018, 6:38 AM
    afterEvaluate {
            extensions.findByName('kapt')?.arguments{
                arg("dagger.formatGeneratedSource","disabled")
                arg("dagger.gradle.incremental","enabled")
            }
        }
    gradle is giving warning
    The following options were not recognized by any processor: '[dagger.gradle.incremental, kapt.kotlin.generated, dagger.formatGeneratedSource]'
    g
    • 2
    • 5
  • s

    Sudhir Singh Khanger

    11/01/2018, 9:53 AM
    class DetailViewModelFactory(private val id: Int) : ViewModelProvider.Factory {
        private val movieRepository: MovieRepository = Injector.getAppComponent().getMovieRepository()
    I was wondering if this piece of code could be rewritten in primary and secondary constructor form where
    MovieRepository
    injected via Dagger 2. (Code:- https://github.com/sudhirkhanger/Genius)
    g
    d
    • 3
    • 13
  • p

    Paul Woitaschek

    11/19/2018, 5:27 PM
    What exactly do you mean by "component-to-component deps"?
    d
    • 2
    • 22
  • w

    william

    11/23/2018, 8:21 PM
    whats the best way to go about constructor injection in kotlin?
    b
    • 2
    • 1
  • s

    sujin

    11/25/2018, 5:31 AM
    Has anyone implemented dagger in modular projects? Something like feature wise modular architecture.
    t
    • 2
    • 2
  • w

    william

    12/12/2018, 1:11 AM
    If I have a constructor with default values how can I make it so dagger doesn't try and inject those fields?
    g
    t
    • 3
    • 6
  • b

    bodo

    12/13/2018, 8:56 AM
    Hi. I wanted to implement dynamic features with instant support in my app. It is almost working except di with dagger. in my app module i do not have access to my activity in the feature module. so i can not do the following in my dagger FragmentsModules.kt
    @ContributesAndroidInjector(modules = [FooFragmentModule::class])
    abstract fun bindFooFragment(): FooFragment -> FooFragment can not be accessed
    Does someone have an solution for this issue?
    :stackoverflow: 1
    r
    • 2
    • 1
  • j

    juliocbcotta

    12/21/2018, 4:28 PM
    kapt {
    
        arguments {
            arg('dagger.gradle.incremental')
            arg('dagger.formatGeneratedSource', 'disabled')
            arg('dagger.fastInit', 'enabled')
        }
    }
    Should I place it in all gradle modules that uses dagger ?
    g
    • 2
    • 1
  • h

    hmole

    01/09/2019, 4:11 PM
    Anyone faced the issue with completely random
    method does not override or implement a method from a supertype
    . Ide doesn't show any errors in my generated component, but
    javac
    can't compile it and fails with this message. First time i'm seeing it and nothing on google.
    • 1
    • 1
Powered by Linen
Title
h

hmole

01/09/2019, 4:11 PM
Anyone faced the issue with completely random
method does not override or implement a method from a supertype
. Ide doesn't show any errors in my generated component, but
javac
can't compile it and fails with this message. First time i'm seeing it and nothing on google.
applying
java
plugin after the
kotlin
one fixes the issue
View count: 3