Android无法导入RecyclerView和CardView

我无法导入RecyclerView& CardView虽然看起来很琐碎.这是gradle.build脚本的相关部分:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "23.0.0"

    lintOptions {
        abortOnError false
    }

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 21
        versionCode 1
        versionName "1"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main {
            java {
                srcDir 'src/main/java'
            }
            resources {
                srcDir 'src/../lib'
            }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.1'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.android.support:recyclerview-v7:21.0.+'
    compile 'com.google.android.gms:play-services:7.8.+'
}

同步&构建任务正常执行,因此似乎实际下载了依赖项.在某些活动中,我尝试导入android.support.v7.widget.RecyclerView;它不承认包裹.

也许是SDK API版本问题?注意我需要最小11和目标最大22.

最佳答案
您需要更改buildToolsVersion.请参阅以下代码.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.0.2"

    defaultConfig {

        minSdkVersion 11
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    compile 'com.android.support:recyclerview-v7:21.0.0'
    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.android.support:palette-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.android.support:support-v4:21.0.3'
    compile files('libs/picasso-2.2.2.jar')
    compile project(':Cropper')
    compile project(':library')
    compile project(':quickScroll')

}

转载注明原文:Android无法导入RecyclerView和CardView - 代码日志