您的位置:首页 > 移动开发 > Android开发

【Android每周专题】Android中maxSdkVersion、minSdkVersion、targetSdkVersion、以及project.properties中的target

2016-08-01 14:30 507 查看
本系列文章均为A2BGeek原创,转载务必在明显处注明:

转载自A2BGeek的【Android每周专题】系列,原文链接:http://blog.csdn.net/a2bgeek/article/details/8203583

maxSdkVersion和minSdkVersion

1、maxSdkVersion

程序被安装的时候,如果目标设备的API版本大于maxSdkVersion,程序将无法安装;或者手机OTA升级后都需要检查升级前已有的程序,如果程序的maxSdkVersion小于手机当前的API版本,那么将被删除。官方文档的原话是:In
either case, if the application's
maxSdkVersion
attribute is lower than the API Level used by the system itself, then the system will not allow the application to be installed. In the case of re-validation after system update, this effectively
removes your application from the device.

细心的开发者也许会发现,升级过SDK之后(我的是4.3的SDK),新创建的应用程序已经没有这个属性了,为什么呢?

首先,新版本的系统是完全向后兼容的,你没有必要设置这个属性去阻止你的程序安装在新平台上。http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels

其次,如果你指定了这个属性,那么用户的手机系统升级后可能会删除你的应用。

2、minSdkVersion

安装程序的时候,如果目标设备的API版本小于minSdkVersion,程序将无法安装。官方文档的原话是:The Android system will prevent the user from installing the application if the system's API Level is lower than the
value specified in this attribute.

targetSdkVersion

首先需要来说明一下兼容性问题。

一、向前兼容

为老版本系统开发的程序,在新版本的系统上同样可以运行。因为most changes in the APIare additive and introduce new or replacement functionality. As parts of the APIare upgraded, the older replaced parts
are deprecated but are not removed, sothat existing applications can still use them. In a very small number of cases,parts of the API may be modified or removed, although typically such changes areonly needed to ensure API robustness and application or system
security. Allother API parts from earlier revisions are carried forward withoutmodification.

下面实测一下向前兼容,我用2.3的SDK编译,完全可以运行
a828
在4.3的系统上,只不过外观还是2.3系统下的外观(这是Theme的原因,使用2.3编译是无法使用HOLO主题的),可以看到navbar右侧的那三个点就是向前兼容的结果(menu):



二、向后兼容

与向前兼容的定义相似,只不过如果程序用到了老版本系统没有的API,那么是无法在老版本系统上运行的。那么该怎么办呢?可以参考这篇文章http://android-developers.blogspot.com/2010/07/how-to-have-your-cupcake-and-eat-it-too.html

下面来说targetSdkVersion

先举个例子来说(目标设备是运行的是Android4.3系统,程序使用android-18编译):

1、新建一个工程,targetSdkVersion默认为18



2、修改targetSdkVersion为10



细心的读者一定会发现在底部navbar的右侧,多了一个菜单按钮。

下面来说一下targetSdkVersion的含义。

targetSdkVersion是控制向前兼容行为的。注意兼容行为指的只是功能而不是外观(Theme),拿menu来说,如果指定targetSdkVersion为10就是告诉系统程序要用2.3下的特性运行,2.3是有菜单的,所以系统就在navbar右侧加了一个菜单按钮。也就是说targetSdkVersion可以停用向前兼容的行为,正如targetSdkVersion为18显示出来那样。

project.properties中的target

指定编译的时候使用的api版本,改了这个的话你的工程中的android.jar也会跟着改变,同时一些主题的应用也会受到影响。

总结一下:

minSdkVersion、maxSdkVersion  安装的时候起作用

targetSdkVersion   运行的时候起作用

project.properties中的target
   编译的时候起作用

参考资料:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐