Android 最小 SDK 版本/目标 SDK 版本与编译 SDK 版本有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24510219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:19:16  来源:igfitidea点击:

What is the difference between min SDK version/target SDK version vs. compile SDK version?

androidandroid-studio

提问by Tobias

What are the differences between "min sdk version/target sdk version" and "compile sdk version"? I know what min and target sdk means, but what does compile sdk version mean?

“最小sdk版本/目标sdk版本”和“编译sdk版本”有什么区别?我知道 min 和 target sdk 是什么意思,但是编译 sdk 版本是什么意思?

In Eclipse, I have min/max and target sdk, but in android studio there are these three settings.

在 Eclipse 中,我有 min/max 和 target sdk,但在 android studio 中有这三个设置。

回答by Matt

The min sdk versionis the earliest release of the Android SDK that your application can run on. Usually this is because of a problem with the earlier APIs, lacking functionality, or some other behavioural issue.

分SDK版本是Android SDK的最早发行您的应用程序都可以运行。通常这是因为早期 API 存在问题、缺乏功能或其他一些行为问题。

The target sdk versionis the version your application was targetedto run on. Ideally, this is because of some sort of optimal run conditions. If you were to "make your app for version 19", this is where that would be specified. It may run on earlier or later releases, but this is what you were aiming for. This is mostly to indicate how current your application is for use in the marketplace, etc.

目标SDK版本为您的应用程序的版本针对上运行。理想情况下,这是因为某种最佳运行条件。如果您要“为版本 19 制作您的应用程序”,这就是指定的位置。它可能会在较早或较晚的版本上运行,但这正是您的目标。这主要是为了表明您的应用程序在市场上的使用程度等。

The compile sdk versionis the version of android your IDE (or other means of compiling I suppose) uses to make your app when you publish a .apkfile. This is useful for testing your application as it is a common need to compile your app as you develop it. As this will be the version to compile to an APK, it will naturally be the version of your release. Likewise, it is advisable to have this match your target sdk version.

编译SDK版本是Android平台的IDE(或编译,我想等手段)使用,让您的应用程序时,您发布的版本.apk文件。这对于测试您的应用程序很有用,因为在您开发应用程序时通常需要对其进行编译。由于这将是编译为 APK 的版本,因此它自然是您发布的版本。同样,建议将此与您的目标 sdk 版本相匹配。

回答by yoAlex5

The formula is

公式是

minSdkVersion <= targetSdkVersion <= compileSdkVersion

minSdkVersion <= targetSdkVersion <= compileSdkVersion

minSdkVersion- is a marker that defines a minimum Android version on which application will be able to install. Also it is used by Lint to prevent calling API that doesn't exist. Also it has impact on Build Time. So you can use build flavors to override minSdkVersion to maximum during the development. It will help to make build faster using all improvements that the Android team provides for us. For example some features Java 8 are available only from specific version of minSdkVersion.

minSdkVersion- 是一个标记,用于定义可以安装应用程序的最低 Android 版本。Lint 也使用它来防止调用不存在的 API。它还对构建时间有影响。因此,您可以在开发过程中使用构建风格将 minSdkVersion 覆盖到最大值。使用 Android 团队为我们提供的所有改进将有助于加快构建速度。例如,Java 8 的某些功能只能从特定版本的 minSdkVersion 中获得。

targetSdkVersion- says Android system to turn on specific behavior changes.

targetSdkVersion- 表示 Android 系统开启特定的行为改变。

For example:

例如:

  • Starting in Android 6.0 (API level 23) Runtime Permissionswere introduced. If you set targetSdkVersionto 22 or lower your application does not ask a user for some permission in run time.

  • Starting in Android 8.0 (API level 26), all notificationsmust be assigned to a channel or it will not appear. On devices running Android 7.1 (API level 25) and lower, users can manage notifications on a per-app basis only (effectively each app only has one channel on Android 7.1 and lower).

  • Starting in Android 9 (API level 28), Web-based data directories separated by process. If targetSdkVersionis 28+ and you create several WebViewin different processes you will get java.lang.RuntimeException

  • 从 Android 6.0(API 级别 23)Runtime Permissions开始引入。如果您设置targetSdkVersion为 22 或更低,您的应用程序在运行时不会要求用户授予某些权限。

  • 从 Android 8.0(API 级别 26)开始,所有的都notifications必须分配给一个通道,否则它不会出现。在运行 Android 7.1(API 级别 25)及更低版本的设备上,用户只能在每个应用程序的基础上管理通知(实际上,每个应用程序在 Android 7.1 及更低版本上只有一个频道)。

  • 从 Android 9(API 级别 28)开始,Web-based data directories separated by process. 如果targetSdkVersion是 28+ 并且你WebView在不同的过程中创建了几个你会得到java.lang.RuntimeException

compileSdkVersion- actually it is SDK Platform version and tells Gradle which Android SDK use to compile. When you want to use new features or debug .javafiles from Android SDK you should take care of compileSdkVersion. One more example is using AndroidXthat forces to use compileSdkVersion- level 28. compileSdkVersionis not included in your APK: it is purely used at compile time. Changing your compileSdkVersion does not change runtime behavior. It can generate for example new compiler warnings/errors. Therefore it is strongly recommended that you always compile with the latest SDK. You'll get all the benefits of new compilation checks on existing code, avoid newly deprecated APIs, and be ready to use new APIs. One more fact is compileSdkVersion >= Support Library version

compileSdkVersion- 实际上它是 SDK 平台版本并告诉 Gradle 使用哪个 Android SDK 进行编译。当您想使用.javaAndroid SDK 中的新功能或调试文件时,您应该注意 compileSdkVersion。另一个例子是使用强制使用级别 28 的AndroidX。不包含在您的 APK 中:它纯粹用于. 更改 compileSdkVersion 不会更改运行时行为。例如,它可以生成新的编译器警告/错误。因此强烈建议您始终使用最新的 SDK 进行编译。您将获得对现有代码进行新编译检查的所有好处,避免新弃用的 API,并准备好使用新 API。还有一个事实是compileSdkVersioncompileSdkVersioncompile timecompileSdkVersion >= Support Library version

You can read more about it here. Also I would recommend you to take a look at the example of migrationto Android 8.0.

您可以在此处阅读更多相关信息。此外,我建议您查看迁移到 Android 8.0的示例。

回答by anuraagy

The min sdk versionis the minimum version of the Android operating system required to run your application.

分SDK版本是运行应用程序所需的Android操作系统的最低版本。

The target sdk versionis the version of Android that your app was created to run on.

目标SDK版本就是Android的版本,您的应用程序创建来运行。

The compile sdk versionis the the version of Android that the build toolsuses to compile and build the application in order to release, run, or debug.

编译SDK版本就是Android的版本的编译工具用来编译和以发行,运行,或调试构建应用程序。

Usuallythe compile sdk version and the target sdk version are the same.

通常编译sdk版本和目标sdk版本是一样的。

回答by Vinay John

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.

compileSdkVersion:compileSdkVersion 是应用编译所针对的 API 版本。这意味着您可以使用该 API 版本中包含的 Android API 功能(显然也可以使用所有以前的版本)。如果您尝试使用 API 16 功能但将 compileSdkVersion 设置为 15,则会出现编译错误。如果您将 compileSdkVersion 设置为 16,您仍然可以在 API 15 设备上运行该应用程序。

minSdkVersion: The min sdk version is the minimum version of the Android operating system required to run your application.

minSdkVersion:最小 sdk 版本是运行您的应用程序所需的 Android 操作系统的最低版本。

targetSdkVersion: The target sdk version is the version your app is targeted to run on.

targetSdkVersion:目标 sdk 版本是您的应用程序要运行的版本。