2

I have a project (created via this StackOverflow question) that has a module with an Android Instrumented Test. It can be run via a normal Configuration where the module is selected.

This works for Android Gradle plugin <=2.2.3 and >=3.0.0-beta1. But as soon as I change the project to Android Gradle project 2.3.x (2.3.0 -> 2.3.3) I get this error message for my run configuration:

enter image description here

I found no way to get more information or debug this error message in any way. There is nothing highlighted in this window or anywhere else.

Any idea what could be causing this? How can I debug this error message to find out what is wrong with my project?

janpio
  • 10,645
  • 16
  • 64
  • 107
  • Super weird: This question is [the **only** Google search result](https://www.google.de/search?q=%22The+current+project+can+not+be+run%E2%80%9D) for this error message. – janpio Oct 05 '17 at 17:45

1 Answers1

2

Try running the Instrumented tests from the command line in Android Studio. The command is ./gradlew connectedAndroidTest . This should give you an indication of what's going on.

Also, make sure that you have an emulator running or a device plugged in.

The Riddler
  • 107
  • 8
  • I did that - and the tests and build were actually successful. Huh!? Gradle command line doesn't use the run config at all, just the tests, right? – janpio Oct 05 '17 at 17:42
  • Yes, in a sense that you are effectively running a Gradle task which runs your Instrumented tests. If you are using Android Studio UI to run the tests, it uses a default run config template. This varies based on your source set. For example, if you go to an Espresso test in your project, right click and select "Run", it will use the Android Instrumented Tests template. By the same token if you go to a unit test and run it, it will use a local unit test template. You can see full details here https://developer.android.com/studio/run/rundebugconfig.html#android-tests. – The Riddler Oct 06 '17 at 11:12
  • Ok. My test is an Espresso test. When I run the class or method by right click -> "Run", it creates a "Android JUnit" run configuration instead of the expected "Android Instrumented Test" which then fails with an "!!! JUnit version 3.8 or later expected: java.lang.RuntimeException: Stub! ..." error message. If I manually create the correct run configuration (with the module, class or method) I can successfully run it with all Android Gradle versions but 2.3.x where I get the pictured error message. Could the fact that it doesn't recognize it as Instrumentation by itself be a problem? – janpio Oct 06 '17 at 14:24
  • Truth is that Android Studio behaves awkward sometimes. Also there have been many deprecations with Gradle 3.0.0. It is hard to determine exactly what's causing your problem - there may be something wrong with the default configurations. Your best bet is to reset AS to defaults. Here's a useful thread that can help you with that https://stackoverflow.com/questions/19384033/how-to-reset-android-studio – The Riddler Oct 06 '17 at 17:32
  • Also go to File->Invalidate Caches/Restart – The Riddler Oct 06 '17 at 17:35
  • I don't think it is anything with my Android Studio installation - same behavior on virgin installation on other computer. I cloned the [AS source](https://android.googlesource.com/platform/tools/idea) and looked for the error message string, but couldn't find it :/ – janpio Oct 06 '17 at 18:57
  • I downloaded 2.3.3, tested it and everything worked fine. It seems that there is something with your project setup that is causing the issue. Is this a recent project that you are working on? Few things to check: * Gradle plugin version (make sure it's 2.3.3) * Test dependencies (JUnit,..etc) - make sure they are updated (junit should be 4.12) * buildToolsVersion * minSdkVersion – The Riddler Oct 09 '17 at 09:03
  • The project is recent. Here is the list of versions (on the branch with "non working" gradle and plugin version configured): https://github.com/janpio/separate_test_module/blob/broken-gradle/BasicSample/build.gradle#L27-L38 I played around with these, but couldn't figure out a working combination. (Thanks for staying with me) – janpio Oct 10 '17 at 16:05
  • 1
    Will have a look as soon as I can. No worries at all. A strong engineering community is what we need! – The Riddler Oct 10 '17 at 16:24
  • I had a brief look and it seems like you didn't change the Gradle distribution url here https://github.com/janpio/separate_test_module/blob/broken-gradle/BasicSample/gradle/wrapper/gradle-wrapper.properties . Change all occurrences so it matches the Gardle version you're trying to use. – The Riddler Oct 22 '17 at 18:50
  • Gradle plugin 2.3.x corresponds to Gradle 3.3, doesn't it? (See https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle) I think I changed both: https://github.com/janpio/separate_test_module/commit/9b3366a12b32dd846811876ba4d4de320ab1fa4b Did I miss anything? – janpio Oct 23 '17 at 10:03
  • Yes, that's correct. I am a bit confused now which Gradle and plugin version you are trying to use. I downloaded the project and could run it with `com.android.tools.build:gradle:3.0.0-beta6` and `gradle-4.1-all.zip`. – The Riddler Oct 25 '17 at 09:43
  • It works with plugin versions up to 2.2.3 and from 3.0.0-beta1 up. It does _not_ work with 2.3.x (2.3.0 -> 2.3.3). (each time with the [respective Gradle version](https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle)). That's why https://github.com/janpio/separate_test_module/tree/broken-gradle is [plugin 2.3.3](https://github.com/janpio/separate_test_module/blob/broken-gradle/BasicSample/build.gradle#L11) and [Gradle 3.3](https://github.com/janpio/separate_test_module/blob/broken-gradle/BasicSample/gradle/wrapper/gradle-wrapper.properties#L6) – janpio Oct 25 '17 at 09:56
  • Did some further investigation with the versions you pointed out and found that your test dependencies in the separate test module https://github.com/janpio/separate_test_module/blob/broken-gradle/BasicSampleTests/build.gradle are not declared as "androidTestCompile". This is the reason why it's run with a JUnit configuration instead of the Android Instrumented tests. However, changing it does not solve the issue, as the androidTestCompile is not recognised. I am assuming it's around tweaking sourceSets settings, but don't have a solution in mind. – The Riddler Oct 26 '17 at 14:11
  • Also found this thread https://plus.google.com/+GiridharKari/posts/LX3eDYf7deZ that may be of use. Share your progress as you move forward with this issue. – The Riddler Oct 26 '17 at 14:13
  • Yep, your comments re JUnit vs. Android Instrumented Tests make sense, there is no "indication" for Android Studio to know this is an Android Instrumented Test. Workwround: [One can fix the configuration manually](https://github.com/googlesamples/android-testing-templates/issues/26#issuecomment-333993232) - then the tests normally run. Unless of course you are using Gradle plugin 2.3.x (this question) ;) – janpio Oct 26 '17 at 16:32