compileSdkVersion 和 targetSdkVersion 有什么区别? [英] What is the difference between compileSdkVersion and targetSdkVersion?

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

问题描述

我查看了文档 使用 Gradle 构建,但我仍然不确定 compileSdkVersiontargetSdkVersion 之间的区别是什么.

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 属性指定编译目标.

那么,什么是编译目标"?

Well, what is the "compilation target"?

我看到了两种可能的解释方式:

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?

我看到 这个问题 以前有人问过,但一个答案只是引用了文档,这对我来说不清楚.

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

compileSdkVersion 是编译应用程序的 API 版本.这意味着您可以使用该 API 版本(以及所有以前的版本,显然)中包含的 Android API 功能.如果您尝试使用 API 16 功能但将 compileSdkVersion 设置为 15,则会出现编译错误.如果您将 compileSdkVersion 设置为 16,您仍然可以在 API 15 设备上运行该应用,只要您的应用的执行路径不尝试调用任何特定于 API 16 的 API.

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 应该表明您已经在您指定的版本上(大概直到并包括)测试了您的应用程序.这更像是一种认证或签署,您向 Android 操作系统提供了一个提示,提示它应该如何在操作系统功能方面处理您的应用.

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.

例如,如文档所述:

例如,将此值设置为11"或更高允许系统在 Android 3.0 或更高版本上运行时将新的默认主题 (Holo) 应用于您的应用...

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 版本.这将确保您的应用在最新的 Android 设备上看起来尽可能好.如果不指定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天全站免登陆