excilys/androidannotations — Issue #8: Read Android Res xml files at compile time
Author: pyricau
Created: 2012-01-06 10:28:05+00:00
State: open
Labels: Enhancement

py.ricau, Jan 5, 2011
We must find out if we can read the res xml file at compile time.

For instance, it would be nice to check at compile time that a view id exists in a layout.

If anyone has knowledge on this subject when dealing with annotation processing, please let us know.

py.ricau, Jan 12, 2011
Emmanuel Bernard told me that they were reading some hibernate conf files at compile time for Hibernate metadata builder. I'll dig in that direction.

py.ricau, Mar 11, 2011
This does not seem feasible, since Android res files are not in the standard Java resource folder.

See [http://opensource.atlassian.com/projects/hibernate/browse/METAGEN-12 METAGEN-12], they have the same problem with files in META-INF/.
Status: WontFix

py.ricau, Apr 6, 2011
In METAGEN-12, they work around this using Class.getResourceAsStream(). They can do so because META-INF is available in the classpath. However, it's now the case for the AndroidManifest.xml file (as well as res/* files)

We were able to read it using a dirty trick (see http://code.google.com/p/androidannotations/source/browse/trunk/AndroidAnnotations/src/main/java/com/googlecode/androidannotations/helper/AndroidManifestFinder.java?spec=svn752&r=752).

Now that we actually read the AndroidManifest.xml file, we may also read the res/* files, such as res/layout/* to check that the referenced ids in code exists in the layouts.
Status: Accepted

py.ricau, Apr 17, 2011
It seems that Robolectric reads the layout files in a Junit runner... which means they have probably done that in Java, and it might actually help us.

http://pivotal.github.com/robolectric/

py.ricau, Apr 17, 2011
The interesting package : https://github.com/pivotal/robolectric/tree/master/src/main/java/com/xtremelabs/robolectric/res