失败 [INSTALL_FAILED_OLDER_SDK] Android-L

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24457831/
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:11:27  来源:igfitidea点击:

Failure [INSTALL_FAILED_OLDER_SDK] Android-L

androidandroid-5.0-lollipop

提问by TomCB

I'm trying to use the new CardView from Android L. I updated everything in the SDK manager, but I keep getting the following error:

我正在尝试使用来自 Android L 的新 CardView。我更新了 SDK 管理器中的所有内容,但我不断收到以下错误:

Failure [INSTALL_FAILED_OLDER_SDK]

失败 [INSTALL_FAILED_OLDER_SDK]

This is my build.gradlefile:

这是我的build.gradle文件:

apply plugin: 'android'

android {
    compileSdkVersion 'android-L'
    buildToolsVersion '20.0.0'

    defaultConfig {
        applicationId "www.thomascbeerten.com.nieuwetests"
        minSdkVersion 8
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    // Support Libraries
    compile 'com.android.support:support-v4:19.1.0'
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.android.support:gridlayout-v7:19.1.0'
    compile 'com.android.support:mediarouter-v7:19.1.0'
    // compile 'com.android.support:support-v13:19.1.0'
    compile 'com.android.support:recyclerview-v7:+'
}

回答by Eddie

Recently there was a post here regarding the L SDK's incompatibility with prior versions of Android. I've been digging in AOSP repositories for quite a few hours now, and determined that the tools behave this way because they are designed to treat preview platforms differently. If you compile against a preview SDK (android-L), the build tools will lock minSdkVersion and targetSdkVersion to that same API level. This results in the produced application being unable to be installed on devices running older releases of Android, even if your application isn't doing anything specific to L. To make matters worse, the new support libs (CardView, RecyclerView, Palette, etc.) are also locked into the L API level, even though--according to their repository names--they should work on API level 7 just fine (and they do!).

最近这里有一篇关于 L SDK 与之前版本的 Android 不兼容的帖子。我已经在 AOSP 存储库中挖掘了好几个小时,并确定这些工具的行为方式是这样的,因为它们旨在以不同的方式对待预览平台。如果您针对预览版 SDK (android-L) 进行编译,则构建工具会将 minSdkVersion 和 targetSdkVersion 锁定到相同的 API 级别。这导致生成的应用程序无法安装在运行旧版 Android 的设备上,即使您的应用程序没有执行任何特定于 L 的操作。更糟糕的是,新的支持库(CardView、RecyclerView、Palette 等)。 ) 也被锁定在 L API 级别,即使 - 根据他们的存储库名称 - 他们应该可以在 API 级别 7 上正常工作(而且他们确实做到了!)。

See my Reddit post about this here, with a workaround.

在这里查看我的 Reddit 帖子,并提供解决方法。

回答by Skillachie

Once you have the above issues resolved as mentioned by Eddie. You might also run into another error;;

一旦你解决了 Eddie 提到的上述问题。您可能还会遇到另一个错误;;

Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light'.

This will be present in your styles.xml . The quick fix is to replace it with the following below:

这将出现在您的 styles.xml 中。快速修复是将其替换为以下内容:

<?xml version="1.0" encoding="utf-8"?>
 <resources>
<!--<style name="AppTheme" parent="android:Theme.Material.Light">-->
<style name="AppTheme" parent="android:Theme.Holo.Light">
</style>

回答by VJ Vélan Solutions

Change

改变

android {
    compileSdkVersion 'android-L'
    buildToolsVersion '20.0.0'

to

android {
  compileSdkVersion 21
  buildToolsVersion '21.0.2'

Note android-Lis in single quotes but 21isn't. 21is an integer and not a string.

注意android-L是单引号,但21不是。21是整数而不是字符串。

回答by SE13013

I just ran into this problem. This can happen when your min sdk version and built targets are set to a higher API level/OS version than your phone is running. If you're using Android Studio, go to File > Project Structure > and edit relavent settings then Run again.

我刚刚遇到了这个问题。当您的最小 sdk 版本和构建目标设置为比手机运行时更高的 API 级别/操作系统版本时,可能会发生这种情况。如果您使用的是 Android Studio,请转到 File > Project Structure > 并编辑相关设置,然后再次运行。

回答by MinceMan

When you compile with L it actually makes a change during compilation setting your minsdkversion to L. If you want to use RecyclerView or CardView I would recommend checking out RecyclerViewLib. RecyclerView and CardView have been moving into this library so that there is no min version L problem. The author also explained in his blog posthow all L related code was removed to make it safe to use.

当您使用 L 编译时,它实际上会在编译期间将您的 minsdkversion 设置为 L。如果您想使用 RecyclerView 或 CardView,我建议您查看RecyclerViewLib。RecyclerView 和 CardView 已经迁移到这个库中,所以不存在最小版本 L 的问题。作者还在他的博客文章中解释了如何删除所有 L 相关代码以使其安全使用。

To add RecyclerViewLb to your project just add the following line to your dependencies in your build.gradle file:

要将 RecyclerViewLb 添加到您的项目中,只需将以下行添加到您的 build.gradle 文件中的依赖项中:

compile 'com.twotoasters.RecyclerViewLib:library:1.0.+@aar'

You then do not want to add the compile 'com.android.support:recyclerview-v7:+'to your build.gradle as you will get that through RecyclerViewLib.

然后您不想将 加入compile 'com.android.support:recyclerview-v7:+'到您的 build.gradle 中,因为您将通过 RecyclerViewLib 获得它。