testing-samples icon indicating copy to clipboard operation
testing-samples copied to clipboard

Build Failures for android-testing

Open mejohnsn opened this issue 11 years ago • 5 comments

I just did the git clone for the android-testing project about a half-hour ago and imported the project using Android Studio as the instructions suggest. I got a warning message complaining about VCS but no root, so I selected "Add Root". That allowed the import to complete and display files, but with some build errors, to wit:

  1. BasicSample-app: MainActivity won't build because R not found. Of course, I have seen this often enough before in both Eclipse and Android Studio, the solution in either case seems to be about the same. So I am more concerned about:

  2. espresso-BasicSample-app builds and runs, but the test does not build , complaining that it cannot find AndroidJUnit4.class. Even more surprising, in the import android.support.test.runner.AndroidJUnit4, it complains it cannot even find runner, though I do have the directory /opt/adt-bundle-mac-x86_64-20140702/sdk/extras/android/m2repository/com/android/support/test/runner (yes, I installed the bundle under Mac OSX, this was the default at the time) and I followed the instructions (long ago, actually) for downloading the Android Support Repository and Android Support Library. That said, I do have to point out that the instructions for the latter do not actually say to add the mentioned changes to the dependencies in the Gradle files, so I did not follow that part, leaving it up to the imported project to set those (hopefully correctly).

BTW: if adding those dependencies is the way to fix this, then WHICH "Gradle file" are they referring to at https://developer.android.com/tools/testing-support-library/index.html#setup when they say, " add these dependencies in your build.gradle file??

Finally, just in case it is relevant, the contents of the above runner directory contain jars for javadocs and source for runner-0.2 and runner-0.3, nothing for AndroidJUnit4.

mejohnsn avatar Aug 19 '15 01:08 mejohnsn

Thanks for reporting this. Importing and building all the samples is an issue in the latest AS builds. This feature was originally there so that we can run all samples on CI but the plan always was that each sample would be checked out individually. We will update shortly and remove the top lvl build.gradle file and update the READMEs. So please import each sample as a separate project by using the build.gradle in the root of your sample of choice.

slinzner-corp avatar Aug 19 '15 16:08 slinzner-corp

Once I figured you meant to select 'build.gradle' (from, in my example, BasicSample-app) in the file chooser dialog that pops up subsequent to choosing Import Project, I saw that sure enough, BasicSample-app now builds and runs. So that resolves the original issue.

Now the remaining problem is much simpler: for a given project there, where do I find the code that tests it? I expected (based on other examples) something like a package using the same name plus 'Test' in the same module, but I do not even see one in the same project. It looks like the user has to guess which other project is the test.

mejohnsn avatar Aug 20 '15 00:08 mejohnsn

The new build system uses a new structure, tests are now located in src/androidTest/ or src/test/ for unit tests. Hope that helps. Please also check which View filter you have selected in your Android Studio. Choose either "Project", which will show the full project tree or "Android", which has a customized filter especially for Android projects.

slinzner-corp avatar Aug 21 '15 10:08 slinzner-corp

I met the same problem after imported the whole project to Android Studio. :(

Folyd avatar Sep 14 '15 09:09 Folyd

Looks like this does not work anymore in AS 1.3.2 it was never our intention to make all samples importable through a top-lvl build.gradle file. With the next push we will remove the top lvl build.gradle file to avoid confusion

slinzner avatar Sep 14 '15 22:09 slinzner