我已仔细按照 the official guide 中的说明进行操作在我的 Eclipse ADT 3.8 中启用注释。
即Annotation Processing和Factory Path配置正确:
我的 Android 应用程序编译成功。当然,它也可以运行,但是由于预期由 Butter Knife 初始化的 View 保持 null
,我得到了明显的 NPE。
如果我更改配置以生成,例如 .apt_generated_foo_bar
,Eclipse 将创建该文件夹。但是是空的。
关于如何说服 Eclipse 在 .apt_generated
中创建适当的类有什么想法吗?
最佳答案
这个问题(和答案)与这个问题重复:Butterknife does not create anything in .apt_generated directory
首先你需要确保你有一个Android项目和not an Android library项目,因为 Butterknife 使用 a different approach 处理库项目.
为此,请单击Project Properties
并转到Android
部分。有关详细信息,请参阅 the Android documentation :
然后检查project/.factorypath中的这些设置:
<factorypath>
<factorypathentry kind="WKSPJAR" id="/PotlatchClient/libs/butterknife-5.1.2.jar" enabled="true" runInBatchMode="false"/>
</factorypath>
项目/.settings/org.eclipse.jdt.apt.core.prefs:
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=.apt_generated
org.eclipse.jdt.apt.reconcileEnabled=true
项目/.settings/org.eclipse.jdt.core.prefs:
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.processAnnotations=enabled
最后在 Eclipse 中刷新并清理以进行完整重建。
另一个建议的问题是将 JDK 更改为 1.7 意味着您只能针对 Kitkat (4.4) 或更高版本。
关于android - Eclipse 不会为 Butter Knife 生成 .apt_generated 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23420143/