我遵循gradle-experimental:0.1.0.的这指南,在Android 1.3.0 RC1上构建了一个ndk混合项目。
一切正常,但是如果我尝试添加测试库依赖项,我发现不再支持androidTestCompile方法。如下所示:

testCompile也会导致同样的错误。
官方的导游不谈这个。那么,我如何添加测试依赖级-实验性的或者这个版本不支持这个功能?
这是我的build.gradle(项目):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}这是build.gradle(鼠标):
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 22
buildToolsVersion = "23.0.0 rc3"
defaultConfig.with {
applicationId = "co.yishun.onemoment.app"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 22
versionCode = 5
versionName = "2.0 canary"
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
}
android.buildTypes {
release {
isMinifyEnabled = true
proguardFiles += file('proguard-rules.pro')
}
}
android.productFlavors {
create("flavor1") {
applicationId = 'com.app'
}
}
android.ndk {
moduleName = "c_test"
}
}
dependencies {
androidTestCompile 'com.android.support.test:runner:0.3'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.3'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
}发布于 2015-07-14 02:44:42
您需要确保您使用的是Gradle 2.5。在File > Project Structure下,导航到Project并将"Gradle版本“设置为2.5。在File > Settings下,导航到Build, Execution, Deployment > Build Tools > Gradle并确保选中“使用默认的Gradle包装器(推荐)”。还可以通过编辑项目的gradle/wrapper/gradle-wrapper.properties文件来编辑Gradle包装。我的看起来是这样的:
#Mon Jul 13 17:55:42 EDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip我按照上面的顺序做了这些步骤,但是在写这篇文章的时候考虑了一下,也许最好是颠倒顺序。我发现我需要在识别所有更改之前完全退出Android并重新启动它。也许有什么东西被藏在某个地方,或者这是我做事顺序的产物。
另外,有关设置Gradle版本的更多信息,请参见这条线。
https://stackoverflow.com/questions/31355192
复制相似问题