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

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


当前回答

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

目标sdk版本是你的应用程序创建运行的Android版本。

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

通常编译sdk版本和目标sdk版本是相同的。

其他回答

minSdkVersion, targetSdkVersion, compileSdkVersion

公式是

minSdkVersion <= targetSdkVersion <= compileSdkVersion

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

targetSdkVersion -如果AndroidOS版本是>= targetSdkVersion,它说Android系统打开特定的(新的)行为变化。*请注意,即使targetSdkVersion为<,其中一些新行为也会默认开启,您应该阅读官方文档。

例如:

Starting in Android 6.0 (API level 23) Runtime Permissions were introduced. If you set targetSdkVersion to 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 notifications must 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 targetSdkVersion is 28+ and you create several WebView in different processes you will get java.lang.RuntimeException

compileSdkVersion - actually it is the SDK Platform version and tells Gradle which Android SDK uses to compile. When you want to use new features or debug .java files from Android SDK you should take care of compileSdkVersion. One more example is using AndroidX that forces to use compileSdkVersion - level 28. compileSdkVersion is 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

你可以在这里阅读更多信息。 另外,我建议你看一下迁移到Android 8.0的例子。

[buildToolsVersion]

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

目标sdk版本是你的应用程序创建运行的Android版本。

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

通常编译sdk版本和目标sdk版本是相同的。

参考-媒介文章由Paulina Sadowska

compileSdkVersion定义哪个Android SDK版本将被Gradle用来编译你的应用。

例如:

在Android 12中,也就是SDK版本31中,引入了一个新的API,让我们能够轻松实现启动画面。在这个新的API中,启动画面可以使用这些属性进行定制:

如果你想在你的应用程序中使用该API,你首先必须:

i)  download SDK version 31 in Android Studio,
ii) and then: update compileSdkVersion to 31 in your app.

只有这样你才能看到这些新属性。只有这样,你才能在你的代码中使用这个新的启动画面API。

2.targetSdkVersion是一个属性,它告诉系统应用程序是在哪个Android版本上设计和测试的。

如果用户在android版本高于应用程序中定义的targetSdkVersion的设备上运行应用程序,对于新的android功能,系统可能会引入一些向后兼容行为,以确保你的应用程序仍然以你设计的方式运行。

例如:

In Android 12 the appearance of custom notifications was changed. Previously they could use the whole notification area, but in Android 12 system applies the standard template to all custom notifications so they look more consistent. If your targetSdkVersion is below 31 system will assume that you haven’t tested that feature and will display notifications in the old way to minimize the risk that notification will not be displayed properly. Only after you update the target SDK version to 31 the new notification appearance will be used.

这里有一个简单明了的方法来理解——

minSdkVersion应该更低,以目标最大覆盖android设备上的应用程序将被安装。

在开发应用程序时需要compileSdkVersion,以使用最新和优化的android api。

tarketSkdVersion是最新的/版本的android操作系统上,你要运行你的应用程序,以实现android资源的充分优化。

注:如有错误,请指正。 谢谢

compileSdkVersion: compileSdkVersion是编译应用程序的API版本。这意味着你可以使用该版本的API中包含的Android API特性(当然也包括之前的所有版本)。如果您尝试使用API 16特性,但将compileSdkVersion设置为15,则会得到编译错误。如果你将compileSdkVersion设置为16,你仍然可以在API 15的设备上运行应用程序。

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

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