Kotlin Error: Dagger does not support injection into private fields
Accidentally I came across to my own answer and have to confess, that in fact it isn't working (at least for my use-case). Please consider Avilio's answer which worked for me also: substitute internal
with lateinit
.
Old answer
Remove internal
modifier. Dagger needs at least package-private access in order to access annotated field. In Kotlin internal
modifier is not a substitution for Java's package-private access modifier.
For detailed explanation of differences between modifiers in Java and Kotlin refer to Fragmented podcast's episode #101 - "Learning Kotlin – visibility modifiers, internal modifier, modules", as well as the official docs.
You have mistake here:
@Inject
internal var mSharedPreferences: SharedPreferences? = null
This looks like you added @Inject
annotation to the KotlinFragment
class
Please change it to this and it will work:
var mSharedPreferences: SharedPreferences? = null
@Inject set
Here is the link to the documentation: https://kotlinlang.org/docs/reference/annotations.html