compileSdkVersion和targetSdkVersion之间的区别是什么? [英] What is the difference between compileSdkVersion and targetSdkVersion?

查看:2063
本文介绍了compileSdkVersion和targetSdkVersion之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过了<一href="http://developer.android.com/sdk/installing/studio-build.html#buildFileBasics">documentation建设有摇篮,但我仍然不知道之间的差异 compileSdkVersion targetSdkVersion

I have looked at the documentation for building with Gradle, but I'm still not sure what the difference between compileSdkVersion and targetSdkVersion is.

所有它说的是:

compileSdkVersion 属性指定编译的目标。

The compileSdkVersion property specifies the compilation target.

那么,什么是编译目标?

Well, what is the "compilation target"?

我看到两种可能的方法来除preT这样的:

I see two possible ways to interpret this:

  1. compileSdkVersion 在构建应用程序,而 targetSdkVersion 使用的编译器的版本是的"API级应用程序的目标。 (如果是这样的话,我会假设 compileSdkVersion 必须大于或等于 targetSdkVersion
  2. 它们的意思是一样的。 编辑目标==API级别的应用目标。
  3. 在其他什么东西?
  1. compileSdkVersion is the version of the compiler used in building the app, while targetSdkVersion is the "API level that the application targets". (If this were the case, I'd assume compileSdkVersion must be greater than or equal to the targetSdkVersion?
  2. They mean the same thing. "compilation target" == "the API level that the application targets"
  3. Something else?

我看到<一href="http://stackoverflow.com/questions/24510219/android-studio-min-skd-version-target-sdk-version-vs-compile-sdk-version"标题=这个问题>这个问题已经问过,但一个答案只是引用了文档,这是什么我不清楚。

I see that this question has been asked before, but the one answer just quotes the doc, which is what is unclear to me.

推荐答案

compileSdkVersion 是应用程序编译对API的版本。这意味着你可以使用包含在该版本的API(以及所有previous版本,很明显)Android的API功能。如果您尝试使用API​​ 16的功能,但设置 compileSdkVersion 15,你会得到一个编译错误。如果设置 compileSdkVersion 16,你仍然可以一个API 15设备上运行的应用程序,只要你的应用程序的执行路径不要尝试调用任何API的特定API 16.

compileSdkVersion

The compileSdkVersion is the version of the API the app is compiled against. This means you can use Android API features included in that version of the API (as well as all previous versions, obviously). If you try and use API 16 features but set compileSdkVersion to 15, you will get a compilation error. If you set compileSdkVersion to 16 you can still run the app on a API 15 device as long as your app's execution paths do not attempt to invoke any APIs specific to API 16.

targetSdkVersion 已无关,与如何您的应用程序被编译或什么的API,你可以利用。该 targetSdkVersion 应该表明您已经测试你对应用程序(presumably直至并包括)指定的版本。这更像是一个认证或签署你给的是Android OS作为提示应该如何处理在OS功能方面的应用程序。

The targetSdkVersion has nothing to do with how your app is compiled or what APIs you can utilize. The targetSdkVersion is supposed to indicate that you have tested your app on (presumably up to and including) the version you specify. This is more like a certification or sign off you are giving the Android OS as a hint to how it should handle your app in terms of OS features.

例如,作为 规定的文档:

For example, as the documentation states:

例如,将该值设置为11或更高版本在Android 3.0或运行时,允许系统到一个新的默认主题(河洛),适用于您的应用程序更高...

For example, setting this value to "11" or higher allows the system to apply a new default theme (Holo) to your app when running on Android 3.0 or higher...

Android操作系统,在运行时,可能会改变你如何应用程序是程式化或根据此值操作系统的情况下,否则执行。但是也有一些由这个值的影响几个其它已知的例子和该列表可能随着时间的推移仅增加

The Android OS, at runtime, may change how your app is stylized or otherwise executed in the context of the OS based on this value. There are a few other known examples that are influenced by this value and that list is likely to only increase over time.

对于所有实用的目的,大多数应用程序会想设置 targetSdkVersion 的API的最新版本。这将确保您的应用程序看起来一样好,可能在最新的Andr​​oid设备。如果不指定 targetSdkVersion ,则默认为的minSdkVersion

For all practical purposes, most apps are going to want to set targetSdkVersion to the latest released version of the API. This will ensure your app looks as good as possible on the most recent Android devices. If you do not specify the targetSdkVersion, it defaults to the minSdkVersion.

这篇关于compileSdkVersion和targetSdkVersion之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆