Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lint error when upgrading to gradle plugin 3.0 : Missing layout_width or layout_height attributes

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?

like image 288
Yash Avatar asked Nov 30 '25 06:11

Yash


2 Answers

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

like image 166
Yash Avatar answered Dec 01 '25 21:12

Yash


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

like image 28
Zoe stands with Ukraine Avatar answered Dec 01 '25 19:12

Zoe stands with Ukraine