title: Android compiled resources - resources.arsc
body: <p>I am trying to figure out what it mean to "compile resources".</p>
  
  <h3>What I did in order to understand this issue:</h3>
  
  <p>I have read many articles about the subject but didn't find a simple answer.
  The best one I have read was this: <a href="https://stackoverflow.com/questions/6517151/how-does-the-mapping-between-android-resources-and-resources-id-work">How does the mapping between android resources and resources ID work?</a>.</p>
  
  <h3>How I understand it:</h3>
  
  <p>From my understanding, when we compile our project either by ANT (Eclipse) or Gradle (AS).
  We use a tool called <strong>aapt</strong> - Android Asset Packaging Tool which:
  Is used to generate unique IDs for each of our resources, such as our layouts, our styles and more and store them in a lookup table. Then it persists this lookup table by generating two files:</p>
  
  <ol>
  <li>It Generates the R.java file with these unique IDs so we will be able to use our resources from our java code during compilation. </li>
  <li>It generate the resources.arsc file which can be found in resources*.ap_ file.
  This resources.arsc file will later be packed by the apktool to the apk.<br>
  This arsc file format is a format that will be easily mapped and parsed by the device at runtime.</li>
  </ol>
  
  <h3>An Example:</h3>
  
  <p>So to make it simple: lets say I have this in my activity_main.xml:</p>
  
  <pre><code>    &lt;TextView android:id="@+id/my_textView"
          android:text="@string/hello_world" 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  </code></pre>
  
  <p>And I call it from my onCreate using:</p>
  
  <pre><code>findViewById(R.id.my_textView)
  </code></pre>
  
  <p>In my R.java file I will see:</p>
  
  <pre><code>public static final int my_textView=0x7f08003f;
  </code></pre>
  
  <p>Using: aapt dump resources on the generated apk I can see it contains two lines with my_textView:
  ec resource 0x7f08003f com.example.lizi.liortest2:id/my_textView: flags=0x00000000
  resource 0x7f08003f com.example.lizi.liortest2:id/my_textView: t=0x12 d=0x00000000 (s=0x0008 r=0x00)</p>
  
  <h3>What I don't understand:</h3>
  
  <p>I would have thought that this resources.arsc file will not just contain the resource ID but also all the properties I have defined for the view, such as android:layout_width="wrap_content".</p>
  
  <p>So now during runtime when the VM tries to run <code>findViewById(R.id.my_textView)</code>
  How does it know which view to get / its properties to create?</p>
  
  <p>I simply can't understand how it works... Shouldn't this lookup table contain also the properties data?
  And what is this 0x7f08003f number? (Should it represent a value that will later be mapped to physical memory in which the object will be stored?)</p>