我想在Android Studio的类路径中更改库的顺序.我试图在IDE中使用JUnit 4 运行单元测试.这符合这些幻灯片中的说明.
我想知道是否可以通过Android Studio 的运行配置配置库的顺序 - 幻灯片中的其他建议?
第一次尝试是在项目模块的" 依赖关系"选项卡中更改" 项目结构"对话框中的依赖项顺序,如屏幕截图所示.
第二个猜测是在build.gradle
文件中包含类路径配置.对此有一些模糊的想法:
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
资料来源:[1 ],[ 2 ]
小智.. 7
我使用以下任务来确保最后列出SDK依赖项:
task pushDownJdkDependency { def imlFile = file("ui.iml") doLast { try { def parsedXml = (new XmlParser()).parse(imlFile) def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' } parsedXml.component[1].remove(jdkNode) new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': "Android API 18 Platform", 'jdkType': 'Android SDK']) def writer = new StringWriter() new XmlNodePrinter(new PrintWriter(writer)).print(parsedXml) imlFile.text = writer.toString() } catch (FileNotFoundException e) { // nop, iml not found } } }
确保使用正确的SDK标识符.然后将任务挂钩到构建过程中:
gradle.projectsEvaluated { preBuild.dependsOn(pushDownJdkDependency) }
除此之外,将任务添加到运行配置中.不幸的是,由于缺乏声誉,我无法发布图片.
我使用以下任务来确保最后列出SDK依赖项:
task pushDownJdkDependency { def imlFile = file("ui.iml") doLast { try { def parsedXml = (new XmlParser()).parse(imlFile) def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' } parsedXml.component[1].remove(jdkNode) new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': "Android API 18 Platform", 'jdkType': 'Android SDK']) def writer = new StringWriter() new XmlNodePrinter(new PrintWriter(writer)).print(parsedXml) imlFile.text = writer.toString() } catch (FileNotFoundException e) { // nop, iml not found } } }
确保使用正确的SDK标识符.然后将任务挂钩到构建过程中:
gradle.projectsEvaluated { preBuild.dependsOn(pushDownJdkDependency) }
除此之外,将任务添加到运行配置中.不幸的是,由于缺乏声誉,我无法发布图片.