我在使用gradle在Android Studio中构建测试时遇到问题。据我所知,它的测试编译中似乎没有包含AppCompat v7的资源,这意味着我的自定义样式引用了一大堆无法“看到”的AppCompat样式。这导致下面的一堆错误。
它非常适用于常规的非测试构建,样式正确应用,项目构建/安装/执行正常,没有错误。如何解决此错误?
完全gradle错误:
Execution failed for task ':processDebugTestResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/me/Android Studio/sdk/build-tools/android-4.4/aapt package -f --no-crunch -I /home/me/Android Studio/sdk/platforms/android-19/android.jar -M /home/me/Development/Android/MyApp/build/manifests/test/debug/AndroidManifest.xml -S /home/me/Development/Android/MyApp/build/res/all/test/debug -A /home/me/Development/Android/MyApp/build/assets/test/debug -m -J /home/me/Development/Android/MyApp/build/source/r/test/debug -F /home/me/Development/Android/MyApp/build/libs/MyApp-debug-test.ap_ --debug-mode
Error Code:
1
Output:
/home/me/Development/Android/MyApp/build/res/all/test/debug/values/values.xml:113: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.ActionBar'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values/values.xml:116: error: Error: No resource found that matches the given name: attr 'titleTextStyle'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values-v11/values.xml:11: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.ActionBar'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values-v14/values.xml:11: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.ActionBar'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values/values.xml:119: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.ActionButton'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values-v11/values.xml:17: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.ActionButton'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values-v14/values.xml:17: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.ActionButton'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values/values.xml:123: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.ActionBar.TabView'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values/values.xml:127: error: Error: No resource found that matches the given name: attr 'dividerPadding'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values/values.xml:126: error: Error: No resource found that matches the given name: attr 'showDividers'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values-v11/values.xml:21: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.ActionBar.TabView'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values-v14/values.xml:21: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.ActionBar.TabView'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values/values.xml:131: error: Error retrieving parent for item: No resource found that matches the given name '@style/TextAppearance.AppCompat.Widget.ActionBar.Title'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values-v11/values.xml:29: error: Error retrieving parent for item: No resource found that matches the given name '@style/TextAppearance.AppCompat.Widget.ActionBar.Title'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values-v14/values.xml:29: error: Error retrieving parent for item: No resource found that matches the given name '@style/TextAppearance.AppCompat.Widget.ActionBar.Title'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values/values.xml:136: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values/values.xml:139: error: Error: No resource found that matches the given name: attr 'actionBarStyle'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values/values.xml:141: error: Error: No resource found that matches the given name: attr 'actionBarTabBarStyle'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values/values.xml:140: error: Error: No resource found that matches the given name: attr 'actionModeBackground'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values-v11/values.xml:34: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat'.
/home/me/Development/Android/MyApp/build/res/all/test/debug/values-v14/values.xml:34: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat'.
的build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.0+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:18.0+'
compile "com.android.support:appcompat-v7:18.0.+"
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest {
java.srcDirs = ['tests']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
lintOptions {
abortOnError false
}
}
值/ styles.xml:
<resources>
<style name="CPTheme" parent="@style/Theme.AppCompat">
<item name="android:textColor">@color/cp_text</item>
<item name="android:windowBackground">@color/cp_background_light</item>
<item name="actionBarStyle">@style/CPThemeActionBar</item>
<item name="actionModeBackground">@color/cp_titlebar_background</item>
<item name="actionBarTabBarStyle">@style/CPThemeTabBar</item>
</style>
<style name="CPThemeActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@color/cp_titlebar_background</item>
<item name="android:textColor">@color/cp_text</item>
<item name="titleTextStyle">@style/CPThemeTitleTextStyle</item>
</style>
<style name="CPThemeTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/cp_text</item>
<item name="android:background">@color/cp_titlebar_background</item>
</style>
<style name="CPThemeTabBar"
parent="@style/Widget.AppCompat.ActionBar.TabView" >
<item name="android:background">@color/cp_background_light</item>
<item name="android:divider">?android:attr/actionBarDivider</item>
<item name="showDividers">middle</item>
<item name="dividerPadding">12dp</item>
<item name="android:padding">0dp</item>
</style>
<style name="CPThemeActionBarButton" parent="@style/Widget.AppCompat.ActionButton">
<item name="android:background">@color/cp_titlebar_background</item>
</style>
</resources>
values / styles-v11.xml和values / styles-v14.xml(它们是彼此的复制粘贴):
<resources>
<style name="CPTheme" parent="@style/Theme.AppCompat">
<item name="android:textColor">@color/cp_text</item>
<item name="android:windowBackground">@color/cp_background_light</item>
<item name="android:actionBarStyle">@style/CPThemeActionBar</item>
<item name="android:actionModeBackground">@color/cp_titlebar_background</item>
<item name="android:actionBarTabBarStyle">@style/CPThemeTabBar</item>
</style>
<style name="CPThemeActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@color/cp_titlebar_background</item>
<item name="android:textColor">@color/cp_text</item>
<item name="android:titleTextStyle">@style/CPThemeTitleTextStyle</item>
</style>
<style name="CPThemeTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/cp_text</item>
<item name="android:background">@color/cp_titlebar_background</item>
</style>
<style name="CPThemeTabBar"
parent="@style/Widget.AppCompat.ActionBar.TabView" >
<item name="android:background">@color/cp_background_light</item>
<item name="android:divider">?android:attr/actionBarDivider</item>
<item name="android:showDividers">middle</item>
<item name="android:dividerPadding">12dp</item>
<item name="android:padding">0dp</item>
</style>
<style name="CPThemeActionBarButton" parent="@style/Widget.AppCompat.ActionButton">
<item name="android:background">@color/cp_titlebar_background</item>
</style>
<style name="BorderlessButton">
<item name="android:background">@color/cp_background_light</item>
</style>
<style name="ListViewCells">
<item name="android:background">@color/cp_background_dark</item>
<item name="android:textColor">@color/cp_text</item>
</style>
</resources>
答案 0 :(得分:1)