简体   繁体   中英

Android studio doesn't find theme with custom gradle configuration for testing

Im trying to do tests in my android application. I have this build.gradle for the root:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

configure(allprojects) { project ->
  buildscript {
    repositories {
      mavenCentral()
      maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
      mavenLocal()
    }
  }
}

project.ext.preDexLibs = !project.hasProperty('disablePreDex')

subprojects {
  group = 'com.firext.android'

  ext.androidBuildToolsVersion    = '19.1.0';
  ext.androidMinSdkVersion        = 18;
  ext.androidCompileSdkVersion    = 19;
  ext.androidTargetSdkVersion     = 19;

  repositories {
    mavenCentral()
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    maven { url "file://${System.getenv("ANDROID_HOME")}/extras/android/m2repository" }
    mavenLocal()
  }

  project.plugins.whenPluginAdded { plugin ->
    if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
      project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
    } else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
      project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
    }
  }
}

apply plugin: 'java'

And this for the build.gradle project module:

buildscript {
  dependencies {
    classpath 'com.android.tools.build:gradle:0.11.+'
  }
}
apply plugin: 'android'

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile project(':libraries:AndroidBootstrap')
  compile 'com.google.code.gson:gson:2.2.4'
  compile 'com.google.android.gms:play-services:3.1.+'
  compile 'com.github.pedrovgs:renderers:1.0.9'
  compile 'com.jakewharton:butterknife:5.0.1'
  compile 'com.etsy.android.grid:library:1.0.4'
  compile 'ch.acra:acra:4.5.0'
  compile 'com.loopj.android:android-async-http:1.4.4'
  compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
  compile 'com.android.support:support-v4:+'

  androidTestCompile 'com.google.guava:guava:14.0.1',
      'com.squareup.dagger:dagger:1.1.0',
      'org.hamcrest:hamcrest-integration:1.1',
      'org.hamcrest:hamcrest-core:1.1',
      'org.hamcrest:hamcrest-library:1.1',
      'com.jakewharton.espresso:espresso:1.1-r2'
}

android {
  compileSdkVersion 19
  buildToolsVersion '19.1.0'

  signingConfigs {

    release {
      //Omitted
    }

    debug {
      testCoverageEnabled = true
    }
  }

  sourceSets {
    main {
      manifest.srcFile 'src/main/AndroidManifest.xml'
      java.srcDirs += 'src/gen'
      res.srcDirs = ['res']
    }
    test {
      java.srcDir file('src/test/java')
      resources.srcDir file('src/test/resources')
    }
    androidTest.setRoot('.')
    androidTest {
      java { srcDirs = [
          'src/test/java'
      ] }
      res.srcDirs = ['res']
      assets.srcDirs = [
          'assets'
      ]
      resources.srcDirs = [
          'src'
      ]
    }
  }

  buildTypes {
    release {
      signingConfig signingConfigs.release
    }
  }

  productFlavors {}
}

This in the manifest:

 <application
      android:allowBackup="false"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/FirextTheme"
      android:name=".FirextApplication">

And this in the styles:

<resources>

    <style name="CustomDialog" parent="android:Theme.Holo.Light.Dialog">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:backgroundDimEnabled">false</item>
        <item name="android:windowIsFloating">false</item>
    </style>

  <style name="FirextTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/ActionBar</item>

  </style>

  <style name="ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">#D30000</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">#ffffff</item>
    <item name="android:displayOptions">useLogo|showHome</item>
  </style>

</resources>

And when i do a sync i get this error:

Error:(29, 24) No resource found that matches the given name (at 'theme' with value '@style/FirextTheme').

Before of this i had a default build.gradle and worked ok, but now dont..Whats wrong?

You should have add defaultConfig to android section:

android {
  compileSdkVersion ext.androidCompileSdkVersion
  buildToolsVersion ext.androidBuildToolsVersion


  defaultConfig {
    minSdkVersion ext.androidMinSdkVersion 
    targetSdkVersion ext.androidTargetSdkVersion 
  }
}

The Holo is available only from 4.0. If you need to support older versions you have to use AppCompat or ActionBarSherlock

Can you change your style.xml to:

<style name="FirextTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/ActionBar</item>
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM