I had the same problem and the testlib depended on lib.
So what I did is:
- use gradle-android-test-plugin (I currently use the deprecated one from 
Jake, but any should do)

- in lib, create a new task to create a jar of the files that will be 
needed by the app

> task packageTests(type: Jar, dependsOn: 'compileDebugTestJava') {
>     from files('src/test/java')
> }
>

- now in the app, I reference the lib code for tests:

> testCompile fileTree(dir: '../libraries/common/common-lib/build/libs', 
> include: 'common-lib.jar')
>

- and I add a dependency so the new lib task will be called automatically:

> project.afterEvaluate{
>     preBuild.dependsOn(":libraries:common:common-lib:packageTests")
> }
>

Perhaps there are more elegant ways to make it work, but it works for me :)

On Sunday, May 25, 2014 1:41:08 PM UTC+2, David Laurell wrote:
>
> A simple solution to your problem would be to move the test code to a 
> separate library that you can use from both your lib and app by using 
> androidTestCompile.
>
> /app
> /lib
> /testlib
>
> Dependencies:
> app compile lib
> app androidTestCompile testlib
> lib androidTestCompile testlib
>
> testlib would be a normal project. You do have to make the testlib not 
> depend on code in lib though..
>
>
> On Friday, May 23, 2014 5:20:50 PM UTC+2, Dan Lew wrote:
>>
>> Hello,
>> I've got a bit of a quandary. Suppose in a project I've got two folders, 
>> one for an app and one for a java lib:
>>
>> /app/
>> /lib/
>>
>> The reason for /lib/ to be separate is so it can be pure java (and run 
>> fast unit tests). Now, we want /app/'s androidTest to use dependencies from 
>> /lib/src/test/.
>>
>> I've managed to at least get the app to compile by specifying the 
>> project's tests as a dependency:
>>
>> dependencies {
>>     androidTestCompile project(':lib').sourceSets.test.output
>> }
>>
>> But in the packaging step it blows up giving me this error:
>>
>> "> Unable to compute hash of <root>/lib/build/resources/test"
>>
>> --debug reveals the problem is in AndroidBuilder:
>>
>> Caused by: com.android.builder.packaging.PackagerException: Unable to 
>> compute hash of <root>/lib/build/resources/test
>> at com.android.builder.AndroidBuilder.packageApk(AndroidBuilder.java:1590)
>> at com.android.builder.AndroidBuilder$packageApk.call(Unknown Source)
>> at 
>> com.android.build.gradle.tasks.PackageApplication.doFullTaskAction(PackageApplication.groovy:91)
>> ... 76 more
>>
>> For some reason it's trying to compute the hash of a directory instead of 
>> individual files, but at this point I'm not sure why.
>>
>> If there's a better way to set this up - or a way to get it to stop 
>> trying to erroneously hash non-jars - I'd appreciate the help.
>>
>> -Daniel
>>
>

-- 
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