gpt4 book ai didi

android - 找不到 Gradle DSL 方法 : 'androidtestcompile()'

转载 作者:行者123 更新时间:2023-11-29 00:11:53 27 4
gpt4 key购买 nike

当我尝试导入从 Eclipse 导出的 build.gradle 文件时出现这样的错误

build.gradle代码:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}

Eclipse 生成的应用模块 build.gradle 如下所示

apply plugin: 'android'

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':android-crop-master:lib:src:main')
compile project(':sharebubbles_menu')
compile project(':braintree-1.2.5-project')
compile project(':facebook')
}

android {
compileSdkVersion 19
buildToolsVersion "19.0.1"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}

// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')

// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}

以下为截图。

enter image description here

最佳答案

您应该更新您正在使用的 gradle/gradle-plugin/AS 的版本。

使用这些版本:

 - AS 1.1.0
- Gradle 2.2.1
- Gradle plugin 1.1.0

然后更改您的构建脚本:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}

还有你的模块脚本:

apply plugin: 'com.android.application'

dependencies {
// The same
}

android {
//Rename your instrumentTest folders to androidTest, e.g. git mv app/src/instrumentTest app/src/androidTest.
// Move the tests to tests/java, tests/res, etc...
androidTestCompile.setRoot('tests')

}
}

关于 Instrumentation Tests 迁移的所有信息都是 here

关于android - 找不到 Gradle DSL 方法 : 'androidtestcompile()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29642836/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com