【问题标题】:Will android application work on lower API levels if I compile it with a higher sdk version?如果我用更高的 sdk 版本编译 android 应用程序,它会在更低的 API 级别上工作吗?
【发布时间】:2016-06-22 08:21:26
【问题描述】:

我使用以下 build.gradle 详细信息构建了我的 android 应用程序:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 8
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
}

当我尝试更改 compileSdkVersion 时,出现了几个错误:

Error:(41, 5) No resource found that matches the given name: attr 'android:borderlessButtonStyle'.
Error:(41, 5) No resource found that matches the given name: attr 'android:buttonBarStyle'.
Error:(41, 5) No resource found that matches the given name: attr 'android:windowCloseOnTouchOutside'.
Error:(46, 5) No resource found that matches the given name: attr 'android:borderlessButtonStyle'.
Error:(46, 5) No resource found that matches the given name: attr 'android:buttonBarStyle'.
Error:(46, 5) No resource found that matches the given name: attr 'android:windowCloseOnTouchOutside'.
Error:(57, 5) No resource found that matches the given name: attr 'android:actionModeCopyDrawable'.
Error:(57, 5) No resource found that matches the given name: attr 'android:actionModeCutDrawable'.
Error:(57, 5) No resource found that matches the given name: attr 'android:actionModePasteDrawable'.
Error:(57, 5) No resource found that matches the given name: attr 'android:buttonBarButtonStyle'.
Error:(57, 5) No resource found that matches the given name: attr 'android:buttonBarStyle'.
Error:(57, 5) No resource found that matches the given name: attr 'android:textColorAlertDialogListItem'.
Error:(57, 5) No resource found that matches the given name: attr 'android:textColorHighlightInverse'.
Error:(57, 5) No resource found that matches the given name: attr 'android:textColorLinkInverse'.
Error:(57, 5) No resource found that matches the given name: attr 'android:windowActionBar'.
Error:(108, 5) No resource found that matches the given name: attr 'android:actionModeCopyDrawable'.
Error:(108, 5) No resource found that matches the given name: attr 'android:actionModeCutDrawable'.
Error:(108, 5) No resource found that matches the given name: attr 'android:actionModePasteDrawable'.
Error:(108, 5) No resource found that matches the given name: attr 'android:buttonBarButtonStyle'.
Error:(108, 5) No resource found that matches the given name: attr 'android:buttonBarStyle'.
Error:(108, 5) No resource found that matches the given name: attr 'android:textColorAlertDialogListItem'.
Error:(108, 5) No resource found that matches the given name: attr 'android:textColorHighlightInverse'.
Error:(108, 5) No resource found that matches the given name: attr 'android:textColorLinkInverse'.
Error:(108, 5) No resource found that matches the given name: attr 'android:windowActionBar'.
Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Spinner.Underlined'.

我浏览了一些链接,但仍有一些疑问:

我担心的是,如果我用 sdk 版本 23 编译这个应用程序,它是否能在 8-23 之间的所有 sdk 版本上运行良好。

此外,将 compileSdkVersion 更改为 8 是否可行且可取,它会以任何方式改变应用程序的性能吗?

非常感谢任何建议。

【问题讨论】:

  • 您是否在使用支持库(即 com.android.support:appcompat-v7:21.0.0)??
  • 我正在使用(编译'com.android.support:appcompat-v7:23.3.0')

标签: android


【解决方案1】:

compileSdkVersion 是您用于编译的 API 版本,因此您可以使用所有包含的 API 功能。此外,您可以使用以前版本的 API。 您可以在 Internet 上找到更多详细信息,例如,在这里: Picking your compileSdkVersion

上面写着:

强烈建议您始终使用最新的 SDK 进行编译。您将获得对现有代码进行新编译检查的所有好处,避免新弃用的 API,并准备好使用新的 API。

【讨论】:

    【解决方案2】:

    是的,只要您不使用更高版本中引入的任何类,该应用程序就可以在较低的 SDK 上运行。例如,您可以看到Fragment 类是在 API 级别 11 中引入的,因此如果您在 API 级别 8 的设备上使用它会崩溃。

    您可以将 AppCompat 库用于新功能的向后兼容版本。支持库有一个Fragment 类,该类兼容直到 API 级别 1(不确定)。

    使用最新的 SDK 进行编译是明智且有利的,因为它具有针对较新平台的优化。

    【讨论】:

      猜你喜欢
      • 2016-02-14
      • 2021-02-16
      • 2018-02-25
      • 2017-12-12
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多