I'm having a problem building tests in Android Studio using gradle. As far as I can tell it doesn't seem to include the resources for AppCompat v7 in its test compilation, which means my custom styles are referencing a whole bunch of AppCompat styles that it can't 'see'. This causes the wad of errors below.
It works totally fine for a regular non-test build, the styles are applied correctly and the project builds/installs/executes just fine with no errors. How can I resolve this error?
Full gradle error:
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
}
}
values/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 and values/styles-v14.xml (they're copy-pastes of each other):
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With