gpt4 book ai didi

android - 错误 : Gradle 'HelloWorld' project refresh failed: Build script error, 找到不支持的 Gradle DSL 方法 : 'setRoot()' !

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:29:16 26 4
gpt4 key购买 nike

您好,我正在使用 AndroidStudio 中的 gradle 测试我的 android 应用程序。我正在使用这个框架 RoboLectric 来完成这一切。

当我将其与 gradle 文件同步时出现错误。伙计们,请分享您对这个问题的看法。

Gradle settings
3:35:14 PM Gradle 'HelloWorld' project refresh failed:
Build script error, unsupported Gradle DSL method found: 'setRoot()'!
Possible causes could be:
- you are using Gradle version where the method is absent
- you didn't apply Gradle plugin which provides the method
- or there is a mistake in a build script
Gradle settings

app文件夹下有build.gradle,我现在有这个

apply plugin: 'android'
apply plugin: 'android-test'

android {
compileSdkVersion 19
buildToolsVersion "19.0.1"

defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

sourceSets {
instrumentTest.setRoot('src/test')
}

dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])

testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
testCompile 'com.squareup:fest-android:1.0.+'
instrumentTestCompile 'junit:junit:4.10'
instrumentTestCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
instrumentTestCompile 'com.squareup:fest-android:1.0.+'
}

在 HelloWorld 中,我有另一个 build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
}
}

allprojects {
repositories {
mavenCentral()
}
}

最佳答案

正如 Peter 在评论中建议的那样,在 android { .... } 中声明 sourceSets。

它对我有用。

android {
compileSdkVersion 19
buildToolsVersion "19.0.1"

defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

sourceSets {
instrumentTest.setRoot('src/test')
}
}

关于android - 错误 : Gradle 'HelloWorld' project refresh failed: Build script error, 找到不支持的 Gradle DSL 方法 : 'setRoot()' !,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22297283/

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