Robolectric: Unable to get resources from exploded-aar with new AS build cache

Created on 5 Mar 2017  路  5Comments  路  Source: robolectric/robolectric

Description

The new Android Studio Build cache no longer creates exploded-aars. The solution to get resources for tests from: https://github.com/robolectric/robolectric/issues/1334 will not work with the build cache enabled (now enabled by default in Android Studio 2.3.

Steps to Reproduce

  1. Have tests that use the project.properties solution from https://github.com/robolectric/robolectric/issues/1334
  2. Upgrade to Android Studio 2.3 and Gradle Plugin 2.3.0 (build cache is enabled by default).
  3. Tests will fail since exploded-aars is not created. See: http://tools.android.com/tech-docs/build-cache

A solution is to disable the build cache but obviously this is not an ideal solution.

Robolectric & Android Version

Robolectric 3.0
Android Studio 2.3
Gradle Plugin 2.3.0
Gradle 3.3

Most helpful comment

I have the exact same issue as @vpratrf using:
AS: 3 canary 7
Robolectric: 3.4-SNAPSHOT
Android build plugin: 3.0.0-alpha7'

Disabling android build-cache by adding:
android.enableBuildCache=false
to my build.gradle file doesn't fix the issue. exploded-aar folder isn't created and I get

Could not find any resource from reference ResName{com.example.app:style/Theme_AppCompat_Light_DarkActionBar} from Style com.example.app:AppTheme with theme with no applied styles

All 5 comments

In the 2.4-previews of the Android Gradle Plugin, in addition to the workaround of disabling the build cache, one must also disable the new dependency resolution mechanism in gradle.properties.

android.enableImprovedDependenciesResolution=false

Otherwise, resources/assets by external module dependencies will not be found.

Able to see similar issue for this configuration:
roboelectric - 3.0
gradle - 3.3
Android Studio - 2.3.3

We have project.properties file pointing to library placed in exploded-aar folder which is not generated once we switch to android gradle plugin 2.3.3

Am I right that latest roboelectric (3.3.2) still has the same issue?

Same issue here :(

Using latest AS canary + latest Robolectric

Could not find any resource from reference ResName{com.example.app:style/Theme_AppCompat_Light_DarkActionBar} from Style com.example.app:AppTheme with theme with no applied styles

I have the exact same issue as @vpratrf using:
AS: 3 canary 7
Robolectric: 3.4-SNAPSHOT
Android build plugin: 3.0.0-alpha7'

Disabling android build-cache by adding:
android.enableBuildCache=false
to my build.gradle file doesn't fix the issue. exploded-aar folder isn't created and I get

Could not find any resource from reference ResName{com.example.app:style/Theme_AppCompat_Light_DarkActionBar} from Style com.example.app:AppTheme with theme with no applied styles

We've revamped resources in Robolectric 4.0 to process the binary resource files + arsc table produced by aapt and the resource handling code is now much closer to that of the framework. This includes changes to parse the merged manifest using the Android platform code.

Mind giving this a try with 4.0 + binary resources by configuring your gradle.build as follows:-

testImplementation "org.robolectric:robolectric:4.0"

android {
  enableUnitTestBinaryResources=true
  testOptions {
    unitTests {
      includeAndroidResources = true
    }
  }
}

We're doing a big bug scrub and trying to be aggressive about it so apologies if this was closed in error, in which case feel free to reopen.

If this is still an issue an example project with failing test would be most helpful.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brettchabot picture brettchabot  路  3Comments

ScottPierce picture ScottPierce  路  3Comments

Jordan-Turgeon picture Jordan-Turgeon  路  3Comments

LeonardoValderas picture LeonardoValderas  路  4Comments

mvdan picture mvdan  路  4Comments