Android App + Library与appcompat版本冲突

时间:2015-03-01 10:18:00

标签: android android-appcompat android-library

我正在开发一个带有库(Android模块)App的应用Lib。他们没有交互时没有问题:导入库后,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'
}

当我启动项目时,Android Studio以某种方式将错误的API级别置于gradle脚本中(或者可能是我忽略了一步)。创建项目后,我在应用程序和库中都有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'.

1 个答案:

答案 0 :(得分:0)

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

您必须使用API​​ 21编译项目。