Android Annotations框架似乎没有生成任何东西
我正在尝试使用 Android 注释 框架,因为它看起来非常强大。我非常坚持基于它配置我的第一个项目。 我遵循了 wiki 的每一步,但它在构建后不会生成任何文件。
因此,当我从清单中请求生成的类时:
<activity android:name=".MyActivity_"
android:label="@string/app_name">
我得到一个异常:
java.lang.ClassNotFoundException
我的活动与 wiki 中的活动完全相同:
@EActivity(R.layout.main)
public class MyActivity extends Activity {
@ViewById
EditText myInput;
@ViewById(R.id.myTextView)
TextView textView;
@Click
void myButton() {
String name = myInput.getText().toString();
textView.setText("Hello "+name);
}
}
有什么想法吗?
编辑:刚刚发现创建了一个目录“.apt_ generated”,但构建后它是空的。
I'm trying to use Android annotations framework because it seems quite powerful. I'm quite stuck to configuring my first project based on it.
I followed every step of the wiki but it doesn't generate any file after a build.
So when I ask for a generated class from the manifest:
<activity android:name=".MyActivity_"
android:label="@string/app_name">
I get an exception:
java.lang.ClassNotFoundException
My activity is exactly the same one as in the wiki:
@EActivity(R.layout.main)
public class MyActivity extends Activity {
@ViewById
EditText myInput;
@ViewById(R.id.myTextView)
TextView textView;
@Click
void myButton() {
String name = myInput.getText().toString();
textView.setText("Hello "+name);
}
}
Any ideas?
EDIT: Just found out a directory ".apt_generated" is made but it's empty after the build.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎是一个 AndroidAnnotations 错误,应该在专用错误跟踪器上报告,此处:http ://code.google.com/p/androidannotations/issues/entry。您还可以使用 AndroidAnnotations 邮件列表,http://groups.google.com/group/androidannotations
首先,我有几个问题:
您使用哪种 IDE:Eclipse、Netbeans、IntelliJ?哪个版本?
您使用 Maven、Ant 还是仅使用您的 IDE 来构建项目?
您的问题可能是由于以下几个原因造成的:未触发注释处理、AA 中的错误或在不属于类路径的文件夹中生成的文件。
在 Eclipse 中,您可以从“Window > Show View > Error Log”视图中获取更多信息。如果触发注释处理,您应该会看到一些有关 AndroidAnnotations 的消息。
This seems to be an AndroidAnnotations bug, and should be reported on the dedicated bug tracker, here : http://code.google.com/p/androidannotations/issues/entry . You could also use the AndroidAnnotations mailing list, http://groups.google.com/group/androidannotations
First, I have a few questions :
Which IDE do you use : Eclipse, Netbeans, IntelliJ ? Which version ?
Do you use Maven, Ant, or only your IDE to build the project ?
Your problem may be due to a few things : annotation processing not triggered, a bug in AA, or the files generated in a folder not part of the classpath.
In Eclipse, you may get more information from the "Window > Show View > Error Log" view. If annotation processing is triggered, you should see some messages about AndroidAnnotations.
对于遇到此问题且主要答案不起作用的其他人,请运行构建,然后在项目中的某处搜索文件 androidannotations.log 。该日志文件是生成的,可能会提示出现了什么问题。
对我来说,它有一条警告消息,指出它无法找到 AndroidManifest.xml。虽然这看起来只是一个警告,但它实际上是错误的原因......找不到我的 AndroidManifest.xml 文件导致它没有生成它应该具有的一些类。
检查您是否有 xml 文件。如果不是,解决方案是显而易见的。如果确实有它,AA 找不到该文件的典型原因是因为它位于非标准位置 - AA 递归地检查其为该 xml 文件生成文件的上方父目录,如果不存在,则会失败。就我而言,我的 AndroidManifest.xml 位于 [项目根目录]/app/src/main 中,它不是直接祖先文件夹,所以这就是问题所在。
您可以指定 xml 文件在项目 build.gradle 中的位置:
}
For other people who are running into this and the leading answer doesn't work, run a build and then search for the file androidannotations.log somewhere in the project. This log file is generated and may hint at what is wrong.
For me, it had a warning message that it could not locate AndroidManifest.xml. Though this seemed like just a warning, it was actually the cause of the error... Not finding my AndroidManifest.xml file resulted in it not generating some of the classes it should have.
Check if you have the xml file. If not, the solution is obvious. If you do have it, the typical reason AA cannot find the file is because it is in a non-standard location -- AA recursively checks the parent directories above where it generates files for this xml file and will fail if it's not there. In my case, my AndroidManifest.xml was located in [project root]/app/src/main which is not a direct ancestor folder so that was the problem.
You can specify where your xml file is in your project build.gradle:
}