Using attributes from API level beyond minSdkVersion

12,986

Solution 1

Unsupported attributes are safely ignored.

From SDK documentation:

When parsing XML resources, Android ignores XML attributes that aren’t supported by the current device. So you can safely use XML attributes that are only supported by newer versions without worrying about older versions breaking when they encounter that code.

Solution 2

For XML attributes, its safe to use attributes from newer APIs (they will simply be ignored as the XML parser won't even look for them on older versions).

Share:
12,986
Michael Garner
Author by

Michael Garner

As a web developer turned Android Developer, I have extensive experience with front end and mobile application development. I have worked on a variety of enterprise level projects and websites. My objectives include a burning desire to always learn more about software, web, and mobile application development and to work somewhere where I can develop my skills and contribute to a project that will make the world better through technology.

Updated on June 16, 2022

Comments

  • Michael Garner
    Michael Garner almost 2 years

    I am new to Android development and am wondering what happens if you use attributes on XML tags from an API level greater than your minSdkVersion.

    For example having:

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="20" />
    

    And then using this:

    <activity android:logo="@drawable/iconwhatever"></activity>
    

    The "android:logo" attribute is from API level 11.

    In Android Studio it gives the following error, but I want to know what could happen if this is left alone:

    Attribute "logo" is only used in API level 11 and higher. (Current min is 9)
    

    Any help regarding this would be greatly appreciated.

  • Michael Garner
    Michael Garner over 9 years
    Great answer. Thank you for the link.
  • tomdelahaba
    tomdelahaba over 6 years
    This is not thruth at all. For example i am just right now getting crashes because of i am using background drawable where the drawable is ripple effect for buttons. It is crashing, because in the drawable i have targetApi lollipop (v21) but i am trying to run the app on api v19. Its crashing on android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
  • Erik
    Erik over 6 years
    @piggy is this because the attribute isn't supported on API 19, or because the attribute's value happens to be unsupported?
  • Steven Jeuris
    Steven Jeuris almost 2 years
    I am targeting API level 31, but have min set to 21. I use usesPermissionFlags on uses-permission and am getting a linter error: Error: Attribute usesPermissionFlags is only used in API level 31 and higher (current min is 21) [UnusedAttribute] Is this then a linter error?