gpt4 book ai didi

android - compileSdkVersion 和 targetSdkVersion 有什么区别?

转载 作者:行者123 更新时间:2023-12-01 23:43:00 24 4
gpt4 key购买 nike

我看过documentation用于使用 Gradle 进行构建,但我仍然不确定 compileSdkVersiontargetSdkVersion 之间有什么区别。

它说的是:

The `compileSdkVersion` property specifies the compilation target.

那么,什么是“编译目标”?

我认为有两种可能的方式来解释这一点:

  1. compileSdkVersion 是构建应用程序时使用的编译器版本,而 targetSdkVersion"API level that the application targets" 。 (如果是这种情况,我会假设 compileSdkVersion 必须大于或等于 targetSdkVersion
  2. 它们的意思是一样的。 “编译目标”==“应用程序目标的API级别”
  3. 还有别的事吗?

我看到this question之前已经被问过,但唯一的答案只是引用了文档,这是我不清楚的。

最佳答案

编译SdkVersion

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

目标SdkVersion

targetSdkVersion 与您的应用程序的编译方式或您可以使用哪些 API 无关。 targetSdkVersion 应该表明您已经在您指定的版本(可能达到并包括)上测试了您的应用程序。这更像是您向 Android 操作系统提供的认证或签字,作为它应如何在操作系统功能方面处理您的应用程序的提示。

例如,如the documentation状态:

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 操作系统在运行时可能会根据此值更改应用程序的样式化方式或在操作系统上下文中的执行方式。还有一些其他已知示例受此值的影响,并且该列表可能只会随着时间的推移而增加。

出于所有实际目的,大多数应用都希望将 targetSdkVersion 设置为最新发布的 API 版本。这将确保您的应用程序在最新的 Android 设备上看起来尽可能良好。如果您不指定 targetSdkVersion,则默认为 minSdkVersion

关于android - compileSdkVersion 和 targetSdkVersion 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58251591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com