Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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"]
            }
        }
    }

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top