【移动开发】targetSdkVersion的作用
在AndroidMenifest.xml中,常常会有下面的语句:
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="10" android:maxSdkVersion="15" />
在project.properties中,会看到下面的语句: target=android-10 如果是使用Eclipse的话,还可能会看到这样的警告:
Attribute minSdkVersion (4) is lower than the project target API level (10)
那么,这里面的minSdkVersion、maxSdkVersion、targetSdkVersion、target四个属性到底有什么区别?
project.properties中的target是指在编译的时候使用哪个版本的API进行编译。 综上,上面的四个值其实是作用于不同的时期:
这四个数值在程序编译时也没有严格的检查,比如说,你可以将minSdkVersion设置的比maxSdkVersion还大,会自动忽略掉错误的maxSdkVersion。
android:targetSdkVersion
- An integer designating the API Level that the application targets. If not set, the defaultvalue equals that given to
minSdkVersion
.This attribute informs the system that you have tested against the target version and thesystem should not enable any compatibility behaviors to maintain your app's forward-compatibilitywith the target version. The application is still able to run on older versions (down to
minSdkVersion
).As Android evolves with each new version, some behaviors and even appearances might change.However, if the API level of the platform is higher than the version declared by your app's
targetSdkVersion
, the system may enable compatibility behaviors to ensure that your appcontinues to work the way you expect. You can disable such compatibilitybehaviors by specifyingtargetSdkVersion
to match the APIlevel of the platform on which it's running. For example, setting this value to "11" or higherallows the system to apply a new default theme (Holo) to your app when running on Android 3.0 orhigher and also disables screencompatibility mode when running on larger screens (because support for API level 11 implicitlysupports larger screens).There are many compatibility behaviors that the system may enable based on the value you setfor this attribute. Several of these behaviors are described by the corresponding platform versionsin the
Build.VERSION_CODES
reference.To maintain your application along with each Android release, you should increasethe value of this attribute to match the latest API level, then thoroughly test your application onthe corresponding platform version.
Introduced in: API Level 4
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html