eclipse android gradle,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,eclipse,gradle

来源: https://codeday.me/bug/20190629/1323300.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值