I have two Android projects, one of which (package name com.adip.sampler ) and a library added to main (package name com.samples.projb ). In both of them in resources I have an integer-array with the same key: my_int_values :
In the main project:
<integer-array name="my_int_values"> <item>10</item> <item>20</item> <item>30</item> <item>40</item> <item>50</item> <item>60</item> <item>70</item> <item>80</item> </integer-array>
in library:
<integer-array name="my_int_values"> <item>34</item> <item>35</item> <item>36</item> <item>37</item> </integer-array>
In the main project from action, if I examine which values from these arrays (both the main project and the library):
protected void showLocalStrings() { Log.d("RESSampler", "In Main: " + Arrays.toString(getResources().getIntArray(com.adip.sampler.R.array.my_int_values))); Log.d("RESSampler", "In Libr: " + Arrays.toString(getResources().getIntArray(com.samples.projb.R.array.my_int_values))); }
then I see this in Logcat:
In Main: [10, 20, 30, 40, 50, 60, 70, 80] In Libr: [10, 20, 30, 40, 50, 60, 70, 80]
It seems that the main project is overriding the values defined in the library array ... I double-checked whether I was reading resources with the correct key, and that is fine. Until I looked in every generated class R In the main project, this is what I have for com.adip.sampler.R.array.my_int_values :
public static final class array { public static final int my_int_values=0x7f060000; }
and in the library project com.samples.projb.R.array.my_int_values :
public static final class array { public static final int my_int_values = 0x7f060000; }
The Android tool generated the same value, so it is not surprising that I get this behavior. I can get rid of this behavior if I changed the key from one of the integer arrays, but imagine that you have several large projects with a lot of resources, dependency libraries, and sooner or later you may encounter this problem: have the same type of resources with the same key value (I checked with string and with string-array and above, it also appears there). So the questions will be as follows:
- Why does this problem appear? Or, if this is not a problem, explains this behavior?
- How to avoid this best? I assume that trying to have some kind of uniqueness in defining keys will do the trick, but developers are usually lazy ...
Several versions of the latest ADT and Eclipse (Juno and Indigo) appear. Tested only on Windows.