Forked from bademux/robolectric-gradle-plugin-fix
Last active
August 29, 2015 14:10
-
-
Save ggrell/ed4adf259e3cdcb68ffd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //build.gradle | |
| //fixes AndroidStudion<>RoboElectric integration | |
| //fixes 'java.lang.RuntimeException: Stub!' and 'NoClassDefFoundError' | |
| gradle.projectsEvaluated { | |
| def imlFile = file(project.name + '.iml') | |
| def parsedXml = (new XmlParser()).parse(imlFile) | |
| def jdkNode = parsedXml.depthFirst().orderEntry.find { it.'@type' == 'jdk' } | |
| def component = jdkNode.parent() | |
| boolean imlChanged = false | |
| if (!component.children().last().equals(jdkNode)) { | |
| println 'iml fix: moving <orderEntry type="jdk"> to the end' | |
| component.remove(jdkNode) | |
| component.append(jdkNode) | |
| imlChanged = true | |
| } | |
| if (component.'output-test'.isEmpty()) { | |
| println 'iml fix: adding <output-test>' | |
| component.appendNode('output-test', ['url': "$project.buildDir/test-classes"]) | |
| imlChanged = true | |
| } | |
| if (imlChanged) { | |
| new XmlNodePrinter(new PrintWriter(new FileWriter(imlFile))).print(parsedXml) | |
| } | |
| } | |
| //fixes 'NoClassDefFoundError' (or run manually 'testDebugClasses' before test) | |
| tasks.findByName("assembleDebug").dependsOn("testDebugClasses") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment