From the android-apt
project page:
The android-apt plugin assists in working with annotation processors in combination with Android Studio. It has two purposes:
Allow to configure a compile time only annotation processor as a dependency, not including the artifact in the final APK or library
Set up the source paths so that code that is generated from the annotation processor is correctly picked up by Android Studio.
You are using Dagger, which uses annotation processing to generate code. The annotation processing code shouldn't be included in the final APK, and you want the generated code to be visible to Android Studio. android-apt
enables this behavior.
This sounds very similar to the provided
scope, but apt
differs from provided
in a few key ways. The first difference is that code generated by an apt
dependency is available to the IDE, whereas code generated by a provided
dependency is not.
Another important difference is that the code in a library using the provided
scope is on the IDE classpath (i.e. you can import the classes and attempt to use them), whereas code in an apt
dependency is not. With provided
, your code will crash at runtime if you don't actually provide the referenced dependencies with a compile
scoped counterpart.
You can find a discussion about apt
vs provided
on this android-apt
issue.
In the case of Dagger, there should be no reason to include the annotation processor and code generator in any of your code (which the provided
scope would allow). Thus the apt
scope is more appropriate.
Update for October 2016:
You probably don't need apt
and the android-apt
plugin anymore. Version 2.2 of the Android Gradle plugin has an annotationProcessor
configuration that you should be using instead.
See more at What's next for android-apt?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…