Android Annotations framework doesn't seem to generate anything
Asked Answered
D

2

10

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.

Delusion answered 22/8, 2011 at 15:27 Comment(1)
Could it be an eclipse issue?Delusion
S
4

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.

Shumway answered 23/8, 2011 at 7:54 Comment(2)
Hey Piwai! thanks for your answer, much appreciated. I was about to post an issue to ggle code but I'm afraid it's a simple issue. I'm using eclipse and only it to build my project. I've attached my error log there : oi51.tinypic.com/21mf2td.jpg Do you have an idea?Delusion
Continuing the discussion on the dedicated bug tracker: code.google.com/p/androidannotations/issues/detail?id=89Delusion
U
0

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:

android {
    defaultConfig {
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["androidManifestFile": "specify_location_of_AndroidManifest.xml_here"]
            }
        }
    }

}

Unbidden answered 11/11, 2020 at 17:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.