Eclipse doesn't generate the .apt_generated folder for Butter Knife

微笑、不失礼 提交于 2019-12-04 23:41:14

问题


I have carefully followed the instructions in the official guide to enable annotations in my Eclipse ADT 3.8.

That is, Annotation Processing and Factory Path are properly configured:

My Android application compiles successfully. It runs too, of course, but I get obvious NPEs due to views that are expected to be initialized by Butter Knife stay null.

If I change the configuration to generate, say .apt_generated_foo_bar, Eclipse will create that folder. But empty.

Any ideas on how I can convince Eclipse to create the appropriate classes in .apt_generated?


回答1:


This question (and answer) duplicates this one: Butterknife does not create anything in .apt_generated directory

First you need to make sure you have an Android project and not an Android library project because Butterknife handles library projects using a different approach.

To do this click Project Properties and go to the Android section. For further details see the Android documentation:

Then check these settings in project/.factorypath:

<factorypath>
    <factorypathentry kind="WKSPJAR" id="/PotlatchClient/libs/butterknife-5.1.2.jar" enabled="true" runInBatchMode="false"/>
</factorypath>

project/.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

project/.settings/org.eclipse.jdt.core.prefs:

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.processAnnotations=enabled

Finally do a refresh in Eclipse and clean to do a full rebuild.

The problem with the other suggestion is changing the JDK to 1.7 means you can only target Kitkat (4.4) or higher.




回答2:


I had same problem, changed: Project>Properties>JavaCompiler>CompilerComliance level from 1.6 to 1.7 now Clean Project, and it worked



来源:https://stackoverflow.com/questions/23420143/eclipse-doesnt-generate-the-apt-generated-folder-for-butter-knife

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!