I should also add, the issue in the Real World has more to do with common 
transitive dependencies; this simplified test case declaring the same 
dependency right there is a bit contrived. Normally you wouldn't need to 
declare your test project's dependency on a library already used by the 
main one , but it's quite common to have a transitive dependency of the 
test suite that happens to be in common, and that's what triggered it for 
us (in our case, we have a test-only helpers library that relies on a base 
helpers library that our main app also depends on through its own 
dependencies). Writing up the test case that way leads to multiple layers 
of projects, though, which makes it a little more confusing to follow.

In that sense, this might be related to Jake Wharton's reported issue about 
androidTest transitive dependencies from a few months back, 
https://code.google.com/p/android/issues/detail?id=65445 , although the 
symptoms here happen at runtime rather than compile-time.

On Tuesday, June 10, 2014 8:27:54 PM UTC-4, Yoni wrote:
>
> I'm getting a consistent app crash during tests when using an app that 
> accesses a resource defined by a library - if that same library is also 
> used by the tests, and when the tests define some of their own resources 
> too.
>
> Code's worth 1000 words and this is weird to try to explain, so I've 
> attached a really minimal project demonstrating the issue, too - if you run 
> the app's test suite with `gradlew app:connectedCheck`, it fails and the 
> app under test crashes with an 
> android.content.res.Resources$NotFoundException. If you build the app 
> without tests it works fine, even when accessing that exact same resource.
>
> As far as I can tell, the resource mapping for the app under test seems to 
> end up mismatched if the tests define their own resources that end up 
> mapped before it. The app then crashes if those resources are accessed by 
> the app under test, since the IDs don't match up properly with what 
> actually ends up in the APK. 
>
> If you look at the various R.java and R.txt files that end up in the build 
> folder after running the tests, you'll see what I mean; the androidTest 
> versions seem to match, but the R.txt and R.java for the app version are 
> out of sync with each other.
>
> (Not every app will run into this in this situation; picking a different 
> name for the string that's defined in the androidTest folder can lead to 
> the tests passing- as long as the name ends up getting mapped later in the 
> R.java/R.txt, the IDs being referenced still match up, but that's only 
> through luck).
>
> This is running against 0.11.1 + buildtools 19.1.0.
>

-- 
You received this message because you are subscribed to the Google Groups 
"adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to