Android应用程序+库与appcompat版本冲突



我正在开发一个带有库(Android模块)Lib的应用程序App。他们在不交互时没有问题:导入库后,Android Studio将build.gradle设置搞砸了,我无法恢复。

我必须瞄准Android 4.4,而不是其他。appcompat库已经安装,对它的依赖已经添加到应用程序和库中(我遵循了本指南:https://developer.android.com/tools/support-library/setup.html)

这是模块的build.gradleapp(对应于应用程序App):

apply plugin: 'com.android.application'
android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "it.mydomain.myapp"
        minSdkVersion 19
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile 'com.android.support:appcompat-v7:21.0.3'
     compile project(':mylib.mydomain.it')
}

这是库的build.gradle

apply plugin: 'com.android.library'
android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.google.android.gms:play-services:6.5.87'
}

不知怎么的,当我开始这个项目时,安卓工作室在渐变脚本中设置了错误的API级别(或者可能是我忽略了一个步骤)。创建项目后,我在应用程序和库中都有API 21级。我修改了两个gradle脚本以使用API 19级,执行了几次清理/重建/构建和其他随机尝试。我在构建项目时仍然会遇到这些错误:

Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Caption'.

以及其他98个类似问题:均与主题问题有关。

还有其他消息,参考值v11v14,如:

/.../build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.3/res/values-v11/values.xml
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
/.../build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.3/res/values-v14/values.xml
Error:(9, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(9, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(9, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(9, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
/.../build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.3/res/values-v21/values.xml
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Body1'.
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Body2'.

'com.android.support:appcompat-v7:21.0.3'需要API 21。

您必须使用API 21编译您的项目。用途:

compileSdkVersion 21

最新更新