It's worth mentioning that "androidTestProvided 
project(':buildDependency')" also causes the resource issue. I'm a little 
surprised that "androidTestCompile project(':buildDependency')" builds and 
runs without other errors. I would have expected the test apk to fail to 
build because the app apk already has :buildDependency classes.

As an experiment, I found that the test passes with "androidTestProvided 
project(':app')" and the build fails with "androidTestCompile 
project(':app')":

Execution failed for task ':app:packageDebugTest'.
> > Duplicate files copied in APK AndroidManifest.xml
>   File 1: 
> /path/to/StringIdLibraryIssue/app/build/intermediates/libs/app-debug-test.ap_
>   File 2: 
> /path/to/StringIdLibraryIssue/app/build/intermediates/libs/app-debug-test.ap_


Ant used to build this successfully but would fail at runtime with dex 
verify errors due to duplicate classes. I certainly prefer the build 
failure.

The test also works when the explicit androidTest dependency is removed 
because test implicitly depends on the app and its dependencies. 
Unfortunately there are cases where the explicit test dependency is 
required such as test infrastructure that depends on app libraries.

On Tuesday, June 10, 2014 2:27:54 PM UTC-10, 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