Android Studio 使用Support.v7和support.v4包遇到的各种问题

使用v7和v4包时会出现这种情况:

/Users/luolawn/Project/AndroidStudioProject/news/ThirdLib/PullToRefreshLibrary/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.0.0/res/values-v11/values.xml
Error:(47, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(47, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(47, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(47, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

v7包中的资源属性不存在,这是由于compileSdkVersion 和buildToolsVersion对应的版本和导入的v7包要求的版本不一样,下面看一个例子:

apply plugin: 'android-library'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

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

dependencies {
    compile fileTree(dir: '../../Libs', include: ['*.jar'])
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.android.support:support-v13:22.0.0'
}
我使用的support都是22.0.0版本,然而compileSdkVersion 20,compileToolsVersion 20所以出现了“没有资源属性”错误,解决方法是:

apply plugin: 'android-library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.0"

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

dependencies {
    compile fileTree(dir: '../../Libs', include: ['*.jar'])
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.android.support:support-v13:22.0.0'
}
修改compileSdkVersion 和compileToolsVersion 对应的数据即可

你可能感兴趣的:(Android开发记录)