Android studio 检查与 API < 19 的兼容性

标签 android android-studio


我有一个具有以下设置的应用程序项目:

android {
  compileSdkVersion 21
  buildToolsVersion '19.1.0'

  defaultConfig {
    minSdkVersion 10
    targetSdkVersion 19
  }
  buildTypes {
    release {

    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
  }
}

我有一个带有 try-with 资源的 block ,该 block 不使用检查 Build.SDK 是否低于 API 19。 我没有从 IDE 收到任何关于它的错误。 我在带有目标 SDK Android 4.1.2 的模拟器上运行了一个程序,一切正常,还在带有 Android 4.2.2 的设备上进行了检查。程序调用此代码,并使用调试器进行检查。 一切都顺利吗?我预计 IDE 可能存在兼容性错误,但事实并非如此。

如果我尝试在 IDE 中使用相同的 minVersionSdk 10 创建新项目,我会从 IDE 收到有关兼容性的错误。 但在我的工作项目中我不明白。 我不知道,除了build.gradle和AndroidManifest.xml之外,是否还有其他兼容性设置?为什么它可以在 API <19 上运行?

更新: 您需要检查 Android Studio 中的 Lint 设置。 编辑 - 检查 Android Lint,在旧版本上调用新方法

最佳答案

Why is it working on API < 19 ?

据此:https://code.google.com/p/android/issues/detail?id=73483它在 API 15 中“大部分工作”,并且您在 API 16 模拟器 (4.1.2) 上进行了测试。

问题提出者指出:

Since it was unhidden in API level 19, try-with-resources is backwards compatible down to API level 15.

Google 成员(member)回复(已编辑):

AutoCloseable was in ics. and it's just an interface; it's javac that emits code to actually do the closing. iirc there are fewer classes that are AutoCloseable in ics than we actually unhid

so "backwards compatible" is a bit misleading. "mostly works" is closer to the truth.

由于不完全兼容,警告来自 API 19。

至于为什么您没有看到警告,我认为这取决于您非常旧的 buildToolsVersion,它可以追溯到 2013 年 12 月。https://developer.android.com/tools/revisions/build-tools.html

You should always keep your Build Tools component updated by downloading the latest version using the Android SDK Manager

关于Android studio 检查与 API < 19 的兼容性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32881671/

相关文章:

android - 通过软件 NFC 模拟卡片

android - Android Studio 中缺少数据库检查器

android-studio - Android Studio 选择错误的目标设备 : always runs app on first selected one

android - 如何将文件下载到本地下载文件夹?

android - 我什么时候应该在使用 avd 的虚拟设备中使用主机 gpu 和快照?

android - 在 '-keepclass' proguard android上缺少EOF

android - 按字符串查找可绘制对象

android - Eclipse 中的传输初始化错误(尝试更新插件)

java - 无法更新 R.java 文件以添加新对象?

java - Android XML 位图和 OutOfMemoryError