Android App +库与appcompat版本冲突

问题描述 投票:3回答:1

我正在开发具有库(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在启动项目时在gradle脚本中放置了错误的API级别(或者也许是我忽略了一个步骤)。创建项目后,我在应用程序和库中的API级别均为21。我修改了两个gradle脚本以使用API​​级别19,执行了几次clean / rebuild / build和其他随机尝试。在构建项目时,我仍然收到这些错误:

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'.
android android-appcompat android-library
1个回答
0
投票

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

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

compileSdkVersion 21
© www.soinside.com 2019 - 2024. All rights reserved.