Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 使用Gradle在Eclipse中添加依赖项大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 Eclipse的Gradle IDE插件,我在build.gradle文件中创建了一个自定义任务:

sourceSets {
    unitTest {
        java.srcDirs = ['tests']
    }
}

dependencies {
    unitTESTCompile files("$project.buildDir/classes/debug")
    unitTESTCompile 'junit:junit:4.11'
    unitTESTCompile 'org.robolectric:robolectric:2.1.1'
    unitTESTCompile 'com.google.android:android:4.0.1.2' 
}

configurations {
    unitTESTCompile.extendsFrom runtime
    unitTestRuntime.extendsFrom unitTESTCompile
}

task unitTest(type:Test,dependsOn: assemblE) {
    description = "run unit tests"
    TESTClassesDir = project.sourceSetS.UnitTest.output.classesDir
    classpath = project.sourceSetS.UnitTest.runtimeClasspath
}

build.dependsOn unitTest

问题是我引用的依赖项没有在Eclipse中添加,我得到导入org.junit.Test;,import org.robolectric.Robolectric;等等,无法解决.我试过点击项目 – > Gradle – >刷新依赖关系但无济于事.

解决方法

自己找到了解决方案.将其添加到build.gradle文件中:

apply plugin: 'eclipse'
eclipse {
    classpath {    
        plusConfigurations += configurationS.UnitTESTCompile
      }
}

然后右键单击项目 – > Gradle – >刷新依赖关系.

大佬总结

以上是大佬教程为你收集整理的android – 使用Gradle在Eclipse中添加依赖项全部内容,希望文章能够帮你解决android – 使用Gradle在Eclipse中添加依赖项所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。