I would like to change the order of libraries in the classpath for Android Studio. I am trying to run unit tests with JUnit 4 from within the IDE. This works following the instruction in these slides.
I wonder if it is possible to configure the order of the libraries - other then suggested in the slides - via the Run Configuration of Android Studio?
The first attempt was to change the order of dependencies in the Project Structure dialog in the Dependency tab of the project module as show in the screenshot.
The second guess was to include the classpath configuration in the build.gradle
file. There are a couple of vague ideas about this:
sourceSets.main.compileClasspath = file("foo.jar") + sourceSets.main.compileClasspath
...
sourceSets.test.compileClasspath = configurations.robo + sourceSets.test.compileClasspath
sourceSets.test.runtimeClasspath = configurations.robo + sourceSets.test.runtimeClasspath
I use the following task to make sure that the SDK dependency is listed last:
make sure you use the correct SDK identifier. Then hook the task into the build process:
Other than that, add the task to your run configuration. Unfortunately I cannot post images due to lack of reputation.
You have to modify the project
.iml
file to have the JDK as the last entry like the following:For a full working example see Robolectric's deckard-gradle sample.