在为Android开发应用程序时,Min和Target SDK版本有什么不同?Eclipse不允许我创建新项目,除非最小版本和目标版本相同!


当前回答

Target sdk是你想要的目标版本,而min sdk是最小的一个。

其他回答

android: minSdkVersion

一个整数,指定应用程序运行所需的最小API级别。如果系统的API级别低于此属性中指定的值,Android系统将阻止用户安装应用程序。您应该始终声明此属性。

android: targetSdkVersion

一个整数,指定应用程序的目标API级别。

With this attribute set, the application says that it is able to run on older versions (down to minSdkVersion), but was explicitly tested to work with the version specified here. Specifying this target version allows the platform to disable compatibility settings that are not required for the target version (which may otherwise be turned on in order to maintain forward-compatibility) or enable newer features that are not available to older applications. This does not mean that you can program different features for different versions of the platform—it simply informs the platform that you have tested against the target version and the platform should not perform any extra work to maintain forward-compatibility with the target version.

更多信息请参考这个URL:

http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

如果你正在制作需要危险权限的应用程序,并将targetSDK设置为23或更高,你应该小心。如果你在运行时不检查权限,你会得到一个SecurityException,如果你在一个try块中使用代码,例如open camera,如果你不检查logcat,就很难发现错误。

OP对这个问题的评论(基本上是说targetSDK不会影响应用程序的编译)是完全错误的!很抱歉我这么直率。

In short, here is the purpose to declaring a different targetSDK from the minSDK: It means you are using features from a higher level SDK than your minimum, but you have ensured backwards compatibility. In other words, imagine that you want to use a feature that was only recently introduced, but that isn't critical to your application. You would then set the targetSDK to the version where this new feature was introduced and the minimum to something lower so that everyone could still use your app.

To give an example, let's say you're writing an app that makes extensive use of gesture detection. However, every command that can be recognised by a gesture can also be done by a button or from the menu. In this case, gestures are a 'cool extra' but aren't required. Therefore you would set the target sdk to 7 ("Eclair" when the GestureDetection library was introduced), and the minimumSDK to level 3 ("Cupcake") so that even people with really old phones could use your app. All you'd have to do is make sure that your app checked the version of Android it was running on before trying to use the gesture library, to avoid trying to use it if it didn't exist. (Admittedly this is a dated example since hardly anyone still has a v1.5 phone, but there was a time when maintaining compatibility with v1.5 was really important.)

再举一个例子,如果你想使用Gingerbread或Honeycomb的特性,你可以使用这个。一些人很快就会得到更新,但许多人,尤其是使用较老硬件的人,可能会继续使用Eclair,直到他们购买新设备。这将允许你使用一些很酷的新功能,但不会排除部分可能的市场。

Android开发人员的博客上有一篇关于如何使用这个功能的非常好的文章,特别是如何设计我上面提到的“在使用之前检查功能是否存在”的代码。

致OP:我写这篇文章主要是为了让将来偶然遇到这个问题的人受益,因为我意识到你的问题很久以前就被问过了。

android:minSdkVersion和android:targetSdkVersion都是Integer值,我们需要在android manifest文件中声明,但两者都有不同的属性。

android:minSdkVersion:这是运行android应用程序所需的最低API级别。如果我们将在较低的API版本上安装相同的应用程序,解析器将出现错误,应用程序不支持的问题将出现。

android:targetSdkVersion: Target sdk version用于设置应用程序的Target API级别。如果manifest中没有声明这个属性,minSdk version将是你的TargetSdk version。这总是正确的,“应用程序支持安装在所有更高版本的API,我们声明为TargetSdk版本”。要使应用程序有限的目标,我们需要声明maxSdkVersion在我们的manifest文件…

对于那些想要总结的人,

android:minSdkVersion

是应用程序支持的最低版本。如果您的设备是低版本的android,应用程序将无法安装。

同时,

android:targetSdkVersion

是API级别,直到你的应用程序被设计运行。这意味着,你的手机系统不需要使用任何兼容性行为来保持向前兼容性,因为你已经测试了这个API。

你的应用仍然会运行在高于给定targetSdkVersion的Android版本上,但Android兼容性行为将开始。

免费的东西- - - - - -

android: maxSdkVersion

如果你的设备的API版本更高,应用程序将无法安装。Ie。这是你允许你的应用程序安装的最大API。

ie。对于MinSDK -4, maxSDK - 8, targetSDK - 8我的应用程序至少在1.6上工作,但我也使用了仅在2.2中支持的功能,如果安装在2.2设备上,这些功能将可见。此外,对于maxSDK - 8,这个应用程序将不会安装在使用API > 8的手机上。

在我写这个答案的时候,Android文档并没有很好地解释这个问题。现在已经解释得很清楚了。点击这里查看