Library projects - PerfectCarl/androidannotations GitHub Wiki

The id fields of the R inner classes of an Android project, such as R.id.someId, are static final constants. This allows us to use them in annotations parameter, which only accept compile time constant values.

To solve problems related to library projects, the Android team decided that the R inner classes fields of a library project would not be static final anymore. Which means we can't use them in annotations in library projects any more.

Prior to AndroidAnnotations 2.7, you can still use it in a library project but with a few limitations :

  • View injection and event binding can be done through "convention naming" instead of specifying the R id in the annotation (eg, if you have a R.id.my_view id, name your @ViewById annotated field myView or your @Click annotated method "myViewClicked").

  • Specifying the layout will have to be done using setContentView in onCreate. View binding & injection still work even if you inject the layout manually.

See this thread, this ACRA issue and this AA issue for more information.

Referencing ids by name

Since AndroidAnnotations 2.7

To enable full AndroidAnnotations support in library projects, we added a new resName attribute on all annotations that accept an Android resource id.

This enables you to specify the resource id name as a String. Please note that AndroidAnnotations checks that the name exists at compile time.

A simple example:

@EActivity(resName="myLayout")
public class MyActivity extends Activity {
	
  @Click(resName={"myButton1", "myButton2"})
  public void someButtonClicked() {
  }
}