title: Android AAR unable to resolve field in styleable
body: <p>I have an "android-commons" library of sorts which gets built into an <code>aar</code> (it's not a jar). One of the things it contains is a custom implementation of "Typeface" views (most of the classes of TextView, e.g. TypefaceTextView, TypefaceButton etc.). To acomplish this, I've declared the following in my <code>attrs.xml</code> (in /res/values):</p>
  
  <pre><code>&lt;attr name="fontName" format="string" /&gt;
  &lt;declare-styleable name="CustomFont"&gt;
      &lt;attr name="fontName" /&gt;
  &lt;/declare-styleable&gt;
  </code></pre>
  
  <p>I could then declare a custom style which specified the font name of a <code>.ttf</code> file within my assets, which the View would parse and set the custom typeface.</p>
  
  <pre><code>// excerpt from TypefaceTextView
  
  public TypefaceTextView(Context context, AttributeSet attrs) {
      super(context, attrs);
      setCustomFont(context, attrs);
  }
  
  private void setCustomFont(Context context, AttributeSet attrs) {
      if (!isInEditMode()) {
          Typefaces.setCustomFont(context, attrs, this);
      }
  }
  </code></pre>
  
  <p>The <code>Typefaces</code> class is a cache for Typefaces and contains utility methods for setting the Typeface to a TextView:</p>
  
  <pre><code>// excerpt from Typefaces
  
  public static void setCustomFont(Context context, AttributeSet attrs, TextView view) {
      String assetPath = getCustomFontPath(context, attrs);
      setCustomFont(context, assetPath, view); // a method that sets the TF to the view
  }
  
  public static String getCustomFontPath(Context context, AttributeSet attrs) {
      TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomFont);
      String assetPath = a.getString(R.styleable.CustomFont_fontName);
      a.recycle();
      return assetPath;
  }
  </code></pre>
  
  <p>Up until now (before Android Studio), for lack of time to modularize this, I had this côde in a few of my projects and it always worked correctly, I could specify <code>fontName</code> in a style which I applied to my Views and all was well.</p>
  
  <pre><code>&lt;style name="TestStyle"&gt;
      &lt;item name="fontName"&gt;ApexNew-Bold.ttf&lt;/item&gt;
      &lt;item name="android:textSize"&gt;14sp&lt;/item&gt;
      &lt;item name="android:textColor"&gt;#ffffff&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p>Now, after a switch to AS, gradle and continuous integration, I put all of this into the mentioned "commons" library which gets built into an aar file. When I add a dependency to the aar, I see all of the Typeface classes and can use them as usual (in code or in layouts). The project builds also, but when running it I get the following exception when inflating a layout that has a TypefaceTextView in it:</p>
  
  <pre><code>unable to resolve static field 2955 (CustomFont) in Lmy/package/name/widgets/R$styleable
  .....
  android.view.InflateException: Binary XML file line #11: Error inflating class my.package.name.widgets.typeface.TypefaceTextView
  </code></pre>
  
  <p>The error is pretty clear, in that it can't find the styleable, but what I can't figure out is why that happens. Here is a <code>tree</code> of the unpacked aar:</p>
  
  <pre><code>AAR
  │   AndroidManifest.xml
  │   classes.jar
  │   R.txt
  │
  ├───aidl
  ├───assets
  └───res
      └───values
              values.xml
  </code></pre>
  
  <p><code>R.txt</code> contains the following:</p>
  
  <pre><code>int attr fontName 0x7f010000
  int[] styleable CustomFont { 0x7f010000 }
  int styleable CustomFont_fontName 0
  </code></pre>
  
  <p><code>/res/values/values.xml</code> contains the following:
  
  
  <pre><code>"1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
  
      &lt;!-- From: file:/C:/Users/vjosip/AndroidStudioProjects/AndroidCommons/widgets/src/main/res/values/attrs.xml --&gt;
      &lt;eat-comment /&gt;
  
      &lt;attr name="fontName" format="string" /&gt;
  
      &lt;declare-styleable name="CustomFont"&gt;
          &lt;attr name="fontName" /&gt;
      &lt;/declare-styleable&gt;
  
  &lt;/resources&gt;
  </code></pre>
  
  <p>Can somebody give an insight as to what could be happening here? I have tried cleaning the project, rebuilding it on a few different machines (including the jenkins CI server) - so far the outcome is the same.</p>