Подтвердить что ты не робот

Android Studio/Gradle не находит ресурсы AppCompat для тестов

У меня возникают проблемы с построением тестов в Android Studio с помощью gradle. Насколько я могу судить, он не включает в себя ресурсы для 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>
4b9b3361

Ответ 1

  • Убедитесь, что вы загрузили последние дополнения (Android Support Library) через SDK-менеджер
  • Android 5.0 SDK через SDK-менеджер
  • Откройте файл build.gradle вашего приложения-модуля и смените файл compileSdkVersion на 21