# Using Dagger 1 and Kotlin

DevFeed: [Using Dagger 1 and Kotlin](<https://devfeed.tech/articles/using-dagger-1-and-kotlin-25103.md>)

Original publisher: [Read original article](<http://michaelevans.org/blog/2016/02/17/using-dagger-1-and-kotlin/>)

Author: Michael Evans

Published: 2016-02-17T18:43:25Z

Content type: article

Language: en

Sources: [Gadget Habit](<https://devfeed.tech/sources/gadget-habit.md>)

Topics: [Dagger](<https://devfeed.tech/topics/dagger.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Android](<https://devfeed.tech/topics/android.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [2](<https://devfeed.tech/tags/2.md>), [android](<https://devfeed.tech/tags/android.md>), [android-development](<https://devfeed.tech/tags/android-development.md>), [beginner](<https://devfeed.tech/tags/beginner.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dagger-2](<https://devfeed.tech/tags/dagger-2.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [development](<https://devfeed.tech/tags/development.md>), [di](<https://devfeed.tech/tags/di.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [property](<https://devfeed.tech/tags/property.md>)

## AI overview

This article explains how to use Dagger 1 with Kotlin in an Android app. It describes Kotlin annotation-processing limitations, Dagger module compilation problems, and a workaround that converts modules to Java classes. It also explains how to inject Kotlin properties by targeting the annotation at the backing field because Dagger does not support method injection.

## Source excerpt

Unless you've been hiding from all the news about Android development, you've likely heard about Kotlin (which hit version 1.0 on Monday!). I've been toying around with it lately (the Kotlin Koans are a great place to start for a beginner) and wanted to try building an app with it - that is, until I hit a few road blocks. Personally, I'm still a fan of Dagger 1 (or as I refer to it, Dagger Classic), and when I started working on my Kotlin app, that's what I was planning to use. I knew Annotation Processing support was a relatively new addition to Kotlin, so I began to search for some information about how to get Dagger to play nicely with the Kotlin compiler. There's a lot of information about using Dagger 2 with Kotlin but not so much about Dagger Classic. Finally, I stumbled upon this article, which said, "Unfortunately, Square's Dagger 1 does not appear to work with Kotlin while Google's Dagger 2 does". Bummer. This didn't really deter me, however, because I'm stubborn like that. So I proceeded to give it a try with kapt1 anyway (which seemed like it might do what I want). Modules The first thing I did was try to create the various Dagger Modules that I'd need, which is where I hit my first roadblock. Attempting to compile my module gave the following error: 1 Error:Modules must not extend from other classes: org.michaelevans.example.AppModule My intial thought was that Kotlin was causing my Module to extend Any, rather than Object. (Any is the root of the class hierarchy in Kotlin, similar to the way that Object is the root of the Java class hierarchy.) Upon closer inspection, that didn't seem to be the issue, but rather than get hung up on this - I just converted my modules to Java classes and decided to come back to this issue later. @Inject So now I had my modules set up, and I went about trying to @Inject some fields on an Activity or two. This yielded another problem: Kotlin doesn't have fields, and we obviously can't do constructor injection on something f