Failure [INSTALL_FAILED_OLDER_SDK] Android-L

2019-01-06 18:13发布

问题:

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:

Failure [INSTALL_FAILED_OLDER_SDK]

This is my build.gradle file:

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:+'
}

回答1:

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!).

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



回答2:

Once you have the above issues resolved as mentioned by 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 . 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>



回答3:

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. 21 is an integer and not a string.



回答4:

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 post how all L related code was removed to make it safe to use.

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

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.



回答5:

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.