【发布时间】:2015-03-01 10:18:00
【问题描述】:
我正在开发一个带有库(Android 模块)Lib 的应用程序 App。他们在不交互时没有问题:导入库后,Android Studio 搞砸了build.gradle 设置,我无法恢复。
我必须以 Android 4.4 为目标 - 仅此而已。 appcompat 库已安装,并且对它的依赖项已添加到应用程序和库中(我遵循本指南:https://developer.android.com/tools/support-library/setup.html)
这是模块的build.gradle:app(对应于应用程序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 个类似的:都与主题问题有关。
还有其他消息,指的是v11、v14等值:
/.../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'.
【问题讨论】:
-
compileSdkVersion 21有什么问题? -
好像真的很奇怪,你用的是这些属性吗?如果您使用的是 v7 库,则不应使用“android:”前缀。
-
我没有使用它们中的任何一个。我只有三个布局文件,他们不使用其中任何一个。
-
@Blackbelt 我是否应该使用 compileSdkVersion 21,即使我只想针对 Android 4.4?
-
我是这么认为的,那东西属于最新的sdk
标签: android android-appcompat android-library