3

In the process of updating to android gradle plugin 3.0, lint has suddenly started failing for views where layout_width and layout_height are defined in the style, rather than at the parent layout. One of the examples :

<Button
    android:id="@+id/btn_positive"
    style="@style/rounded_solid_button"
    android:textAppearance="@style/TextAppearance.ProximaRegularFont"
    android:textSize="@dimen/mini"
    android:text="Ok"/>

and my styles.xml:

<style name="rounded_solid_button">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_gravity">center_horizontal</item>
    <item name="android:gravity">center</item>
    <item name="android:textColor">@color/button_text_color</item>
    <item name="android:textStyle">normal</item>
    <item name="android:textAllCaps">false</item>
    <item name="android:background">@drawable/rounded_solid_button</item>
    <item name="android:layout_marginTop">20dp</item>
    <item name="android:textSize">@dimen/title</item>
    <item name="android:singleLine">true</item>
</style>

Lint fails here stating :

The required layout_width and layout_height attributes are missing

Anybody else faced this issue?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Yash
  • 5,225
  • 4
  • 32
  • 65
  • Cannot repro your issue but I remember seeing false positives about this in the past. Lint ships as part of the "Android SDK Tools" package, make sure it is up-to-date on your CI boxes. – laalto Oct 28 '17 at 14:38
  • able to repro this on local machine as well actually. Wondering if the check has been added/made-buggy with the new gradle plugin. – Yash Oct 28 '17 at 14:49
  • `tools:ignore="RequiredSize"` was the method I used to suppress those false positives back then. – laalto Oct 28 '17 at 14:57
  • 1
    People who are downvoting, you should at least care to explain why ! As I mentioned in one of the answers, it's a bug in lint which I got to know about today itself. I seriously think that downvoting privilage should not be given as easily as it's being given right now. There are many irresponsible people out there who just don't give it a second thought before downvoting anything and don't even care to explain to the OP why they did so !! – Yash Oct 30 '17 at 08:42

2 Answers2

3

Just checked, it's an issue in lint which has not been fixed in the stable release of AS :-/

https://issuetracker.google.com/issues/37138580

Yash
  • 5,225
  • 4
  • 32
  • 65
1

Clean and rebuild the project. It should work, but if it for some reason doesn't anymore you have to declare it in the view tag instead of in styles.xml

Alternatively, cleaning and invalidating the cache (assuming you use Android Studio/IntelliJ) should also do the trick

Zoe
  • 27,060
  • 21
  • 118
  • 148