Gradle Android plugin "androidTestCompile" with AAR dependency 0.9.0 issue

1,795 views
Skip to first unread message

Nicolas Milliard

unread,
Mar 7, 2014, 7:00:38 PM3/7/14
to adt...@googlegroups.com
Hello,

I am having an issue using androidTestCompile with AAR dependencies (Jar deps are working) using:
* Gradle 1.11 
* Gradle Android Tool plugin 0.9.0

How to reproduce
->   Use any AAR dependency with the '"androidTestCompile" scope , like androidTestCompile  'com.jakewharton.espresso:espresso:1.1-r2'

Actual result
-> The java classes are not accessible from the android test source code

When did this bug start happening?
-> I noticed it starting from 0.9.0, might have been present sooner though.

When does the bug occur?
-> Always

Describe any workarounds you have found
-> Change the scope to "compile" solves it but not an appropriate solution

Scott Barta

unread,
Mar 7, 2014, 7:54:52 PM3/7/14
to adt...@googlegroups.com
I tried this earlier today with Studio 0.5.0 and it was working for me. With androidTestCompile, I was able to access the library from java sources under src/androidTest (is this what your test folder is named?), but not in src/main/java.


--
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 adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicolas Milliard

unread,
Mar 7, 2014, 7:59:29 PM3/7/14
to adt...@googlegroups.com
Hum, Yeap my test folder is named androidTest since normal JAR dependencies are working.

Xavier Ducrohet

unread,
Mar 7, 2014, 8:51:57 PM3/7/14
to adt...@googlegroups.com
I haven't changed anything in there so this should work but I'll have to double check Monday.

On Fri, Mar 7, 2014 at 4:00 PM, Nicolas Milliard <niq...@gmail.com> wrote:

--
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 adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Nicolas Milliard

unread,
Mar 11, 2014, 8:21:53 PM3/11/14
to adt...@googlegroups.com
Xavier, I have created a new simple project from Android studio that reproduce the issue. See attached Gradle project.
androidTestCompileIssue.zip

Nicolas Milliard

unread,
Mar 12, 2014, 5:45:19 PM3/12/14
to adt...@googlegroups.com
I got news. Apparently the AAR was not the issue at all. Sorry for that misleading.

So, basically my issue is that AndrioidStudio does not use the `androidTestCompile` scope. If I use the gradle command line, everything works correctly.
When I look at the source code via AndroidStudio, the IDEA shows me the imported classes as error, as if I didn't add them as dependency.

I hope this make my bug clearer.

Nicolas

Nicolas Milliard

unread,
Mar 12, 2014, 5:59:52 PM3/12/14
to adt...@googlegroups.com
For now, duplicating the dependency and set it to provided solves this issue.

Xavier Ducrohet

unread,
Mar 12, 2014, 5:59:31 PM3/12/14
to adt...@googlegroups.com
oh yeah this is a known issue, and should be fixed in 0.5.2

Nicolas Milliard

unread,
Mar 12, 2014, 6:06:12 PM3/12/14
to adt...@googlegroups.com
Awesome thanks! 
You can close the issue you opened here:

Streets Of Boston

unread,
Mar 20, 2014, 5:38:49 PM3/20/14
to adt...@googlegroups.com
I just upgraded to 0.5.2.

The issue still exists.

It compiles fine, but Android Studio still can't recognize the espresso imports. E.g. this one can't be found.

import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;

However, it can find this one without problems:

import org.hamcrest.Matcher;

nic.milliard

unread,
Mar 20, 2014, 6:06:39 PM3/20/14
to adt...@googlegroups.com
Same here. 0.5.2 didn't solve it for me too.


You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/rwRanX8pfX4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+u...@googlegroups.com.

Venkatesh M

unread,
May 19, 2014, 3:19:17 AM5/19/14
to adt...@googlegroups.com, nic.mi...@gmail.com
Same here. Using 0.5.8 and the issue still exists. Is there an issue open for this already?

Richard Guion

unread,
Jun 4, 2014, 3:36:08 PM6/4/14
to adt...@googlegroups.com
Also ran into this issue with androidTestCompile in 0.5.8.  Hope it will be fixed soon.

Richard Guion

unread,
Jun 6, 2014, 2:31:19 PM6/6/14
to adt...@googlegroups.com
Upgraded to Android Studio 0.5.9 - problem still occurs.  You can give automated testing a boost if you fix this.

James Wald

unread,
Jul 18, 2014, 2:53:07 AM7/18/14
to adt...@googlegroups.com
Classes belonging to the dependency "androidTestCompile project(:exampleAarLib)" are not found when androidTest classes are compiled. androidTest classes are only able to access dependency classes when the dependency is declared as "compile project(:exampleAarLib)".

This is a critical issue because it forces us to move our tests into separate test-only library projects. That is the only way we can use "compile project(:exampleAarLib)" without affecting debug and release builds. You may be able to use the "provided" + "androidTestCompile" hack, but I don't have that option because our test libraries depend back onto the library under test in order to provide test fixtures. Declaring both "provided" and "androidTestCompile" results in a circular dependency and a broken build.

I'd appreciate it if anyone on the tools team could at least point me in the right direction. Hoping I'll have some time this weekend to dig into the source again. Mahalo.
Reply all
Reply to author
Forward
0 new messages