Note: 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. For
example, if you set the targetSdkVersion=”11″, your app includes the
ActionBar by default on Android 3.0 and higher. To then add menu items
to the action bar, you need to set android:showAsAction=”ifRoom” in
your menu resource XML. It’s safe to do this in a cross-version XML
file, because the older versions of Android simply ignore the
showAsAction attribute (that is, you do not need a separate version in
res/menu-v11/).
Source: http://developer.android.com/training/basics/supporting-devices/platforms.html
^ Despite this claim eclipse is refusing to compile an unaltered version of fragment basics from the same site here.
The error message given is:
String types not allowed (at ‘layout_width’ with value
‘match_parent’).
Is there anyway I can suppress this error within XML, like some kind of silent tag that states they only apply to a specific API level? Ideally I want the project to work in Eclipse and also maintain 1.6 backwards compatibility.
NOTE: All other errors pertain to R not being generated making this the only first generation error.
The manifest file does contain the line
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />
You can compile in the newer API’s and the application will still work in the old API, thereby getting rid of these errors, as long as you don’t use any of the unsupported features in the .java files without first providing relevant checks. I thought I had to compile against the lowest API not the highest but have tested using a 1.6 AVD to run a project compiled using 4.0 and it worked flawlessly.