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

在使用Android Studio的Support.v7和Support.v4库时,遇到资源找不到的错误,具体表现为在values-v11/values.xml文件中,attr 'android:actionModeShareDrawable'无法匹配。错误源于compileSdkVersion和buildToolsVersion配置不匹配导致的v7包资源属性缺失。解决方案是确保项目配置与库所要求的版本一致。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用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 对应的数据即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值