简体   繁体   English

特定设备的targetSDKVersion、minimumSDKVersion和compileSDKVersion

[英]targetSDKVersion, minimumSDKVersion, and compileSDKVersion for specific device

I'm programming for one specific device and I'm having trouble understanding how I should be setting minsdkversion, compilesdkversion, and targetsdkversion.我正在为一个特定的设备编程,但我无法理解应该如何设置 minsdkversion、compilesdkversion 和 targetsdkversion。 I want to get a compiler error when I'm using a library that doesn't exist for API level 25. Here's what I gatherered.当我使用 API 级别 25 不存在的库时,我想得到一个编译器错误。这就是我收集的内容。 Minsdkversion prevents calling API that doesn't exist for API version. Minsdkversion 阻止调用 API 版本不存在的 API。 Compilesdkversion should always be the latest version. Compilesdkversion 应该始终是最新版本。 Targetsdkversion is what the app was tested against (don't understand what this means). Targetsdkversion 是测试应用程序的对象(不明白这是什么意思)。

minsdkversion-25 compilesdkversion-28 (needed for AndroidX) targetSDKversion-25 minsdkversion-25 编译dkversion-28(AndroidX 需要) targetSDKversion-25

Version settings版本设置

Among those version settings, only minSdkVersion takes effect to detect API level error.在这些版本设置中,只有 minSdkVersion 生效,检测 API 级别错误。 If you'd like to know details of the version settings, see documentation .如果您想了解版本设置的详细信息,请参阅文档

How to let build system report API level error如何让构建系统报API级别错误

For release builds , place "lintOptions" in app/build.gradle and mark "NewApi" as "fatal".对于发布版本,将“lintOptions”放在 app/build.gradle 中,并将“NewApi”标记为“致命”。 Then lintVitalRelease gradle task reports error during compilation.然后 lintVitalRelease gradle 任务编译时报错。

android {

    lintOptions {
        fatal "NewApi"
    }

    compileSdkVersion 30

    defaultConfig {
        minSdkVersion 25
        targetSdkVersion 30

        :
    }
    :
} 

Checking API level manually手动检查 API 级别

In debug builds , the lintOptions above doesn't have any effects because the lint is not included in debug build tasks (there is no lintVitalDebug gradle task).调试构建中,上面的 lintOptions 没有任何效果,因为调试构建任务中不包含 lint(没有 lintVitalDebug gradle 任务)。 So rather, after coding, run "code inspection" manually to detect all the NewApi problems in your code.因此,编码后, 手动运行“代码检查”以检测代码中的所有 NewApi 问题。 If incompatible API uses found, you'll see "calling new methods on older version" error in the inspection result.如果发现不兼容的 API 使用,您会在检查结果中看到“在旧版本上调用新方法”错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM