excilys/androidannotations — Issue #20: Alternative method for providing R ids with Android 4
Author: pyricau
Created: 2012-01-06 11:01:06+00:00
State: open
Labels: Enhancement

In Android 4, the fields of the R inner classes won't be final anymore for library projects (and only for library projects).

This means that those ids cannot be used for switches any more (and we don't really care), but also cannot be use into annotations. That's a problem for us, because the compiler won't allow this any more :

`@ViewById(R.id.myIdFromMyLibraryProject)`

So I think we'll have to provide an alternative way to specify ids, using strings and complete qualified names :

`@ViewById(alt="com.mylibrary.R.id.myIdFromMyLibraryProject")`

This is not perfect (not typesafe any more). Ids may become invalid and you won't notice. We can help with our compile time framework, because when can check that the "com.mylibrary.R.id.myIdFromMyLibraryProject" field exists, and issue a compile error otherwise. Runtime frameworks won't be that lucky (RoboGuice, ACRA...).

The Android team introduced this change to improve the build perfs when using library projects. More on this subject :

http://tools.android.com/tips/non-constant-fields
https://plus.google.com/u/0/109385828142935151413/posts
http://code.google.com/p/acra/issues/detail?id=85