简体   繁体   English

失败[INSTALL_FAILED_OLDER_SDK] Android-L

[英]Failure [INSTALL_FAILED_OLDER_SDK] Android-L

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.gradle file: 这是我的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:+'
}

Recently there was a post here regarding the L SDK's incompatibility with prior versions of Android. 最近有一篇关于L SDK与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. 我已经在AOSP存储库中挖掘了几个小时,并确定这些工具的行为方式是因为它们旨在以不同方式处理预览平台。 If you compile against a preview SDK (android-L), the build tools will lock minSdkVersion and targetSdkVersion to that same API level. 如果您针对预览SDK(android-L)进行编译,则构建工具会将minSdkVersion和targetSdkVersion锁定到相同的API级别。 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!). 这导致生成的应用程序无法安装在运行旧版Android的设备上,即使您的应用程序没有执行任何特定于L的操作。更糟糕的是,新的支持库(CardView,RecyclerView,Palette等)。 )也被锁定在L API级别,即使 - 根据他们的存储库名称 - 他们应该在API级别7上正常工作(他们这样做!)。

See my Reddit post about this here , with a workaround. 点击此处查看我的Reddit帖子,了解相关信息。

Once you have the above issues resolved as mentioned by Eddie. 一旦您解决了Eddie提到的上述问题。 You might also run into another error;; 您可能还会遇到另一个错误;

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 . 这将出现在styles.xml中。 The quick fix is to replace it with the following below: 快速解决方法是使用以下内容替换它:

<?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>

Change 更改

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

to

android {
  compileSdkVersion 21
  buildToolsVersion '21.0.2'

Note android-L is in single quotes but 21 isn't. 注意android-L是单引号但21不是。 21 is an integer and not a string. 21是整数而不是字符串。

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 . 当你使用L进行编译时,它实际上在编译期间进行了更改,将minsdkversion设置为L.如果要使用RecyclerView或CardView,我建议您查看RecyclerViewLib RecyclerView and CardView have been moving into this library so that there is no min version L problem. RecyclerView和CardView已经进入这个库,因此没有最小版本L问题。 The author also explained in his blog post how all L related code was removed to make it safe to use. 作者还在他的博客文章中解释了如何删除所有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获得该compile 'com.android.support:recyclerview-v7:+'

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. 当您的min sdk版本和构建目标设置为比手机运行更高的API级别/操作系统版本时,可能会发生这种情况。 If you're using Android Studio, go to File > Project Structure > and edit relavent settings then Run again. 如果您使用的是Android Studio,请转到文件>项目结构>并编辑相关设置,然后再次运行。

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

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