You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Alternative method for providing R ids with Android 4 #20
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 :
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 :
We could generate an R_ class that would be a copy of the R class (with negative ids) but with final fields, and at compile time we would reference the right R field in the generated code. This would mean we wouldn't need to do any change to @EActivity, and when referencing library project ids you would do @EActivity(R_.layout.someLayout).
I don't know why I wanted to use negative ids. There's no point doing that, we can use the real ids anyway.
Hum. We in fact cannot do that. I just tried, spent some time implementing it and.. the problem is that when doing a full build, the R_ class is removed, and therefore the annotation value cannot be found, leading to a java.lang.reflect.InvocationTargetException.
Activity
pyricau commentedon Feb 2, 2012
Well in fact we should be able to find the R class, so we could probably do this :
@ViewById(alt="myIdFromMyLibraryProject")@EActivity(alt="myLayout")naixx commentedon Jun 15, 2012
Should be very useful. Vote +
pyricau commentedon Jun 21, 2012
Quoting myself in #78 :
I don't know why I wanted to use negative ids. There's no point doing that, we can use the real ids anyway.
pyricau commentedon Jun 21, 2012
Hum. We in fact cannot do that. I just tried, spent some time implementing it and.. the problem is that when doing a full build, the
R_class is removed, and therefore the annotation value cannot be found, leading to ajava.lang.reflect.InvocationTargetException.We'll have to fallback to String attributes.
pyricau commentedon Jun 21, 2012
I'm on it... this is going to be a mega commit :)
Introducing a new resName parameter in annotations to add library sup…
pyricau commentedon Jun 25, 2012
Documentation available