如何配置库的类路径中的Andr​​oid Studio中的顺序? [英] How to configure the order of libraries in the classpath for Android Studio?

查看:354
本文介绍了如何配置库的类路径中的Andr​​oid Studio中的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变的类路径中的Andr​​oid工作室库的顺序。我从在IDE中努力运行单元测试使用JUnit 4。这工作继<一个href=\"http://www.slideshare.net/tobias$p$puss/how-to-setup-unit-testing-in-android-studio\">instruction在这些幻灯片的。

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.

我不知道是否有可能为配置库的顺序 - 其他然后在幻灯片建议 - 通过的运行配置的Andr​​oid的工作室

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.

第二个猜测是包括在的build.gradle 文件中的类路径配置。有一对夫妇的模糊关于这方面的意见:

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


  • 来源:<一个href=\"http://forums.gradle.org/gradle/topics/how_do_i_control_the_order_of_compiletime_classpaths#reply_7726876\">1], [ 2 ]

    • Sources: [1], [2]
    • 推荐答案

      我用下面的任务,以确保该SDK的依赖列在最后:

      I use the following task to make sure that the SDK dependency is listed last:

      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标识符。然后勾任务到构建过程:

      make sure you use the correct SDK identifier. Then hook the task into the build process:

      gradle.projectsEvaluated {
          preBuild.dependsOn(pushDownJdkDependency)
      }
      

      除此之外,该任务添加到您的运行配置。不幸的是,我不能因缺乏信​​誉发表图片。

      Other than that, add the task to your run configuration. Unfortunately I cannot post images due to lack of reputation.

      这篇关于如何配置库的类路径中的Andr​​oid Studio中的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆