当我尝试从github编译导入的project时,我的gradle构建总是以下面的例子失败。
Unable to find method 'org.gradle.api.tasks.testing.Test.getTestClassesDirs()Lorg/gradle/api/file/FileCollection;'
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)</li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes
我按照给出的指示,但没有成功。此外,我无法通过在互联网上搜索错误获得有关错误的任何进一步信息
app \ build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "iammert.com.androidarchitecture"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
/*androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})*/
// testCompile 'junit:junit:4.12'
//support lib
implementation rootProject.ext.supportLibAppCompat
implementation rootProject.ext.supportLibDesign
implementation rootProject.ext.archRuntime
implementation rootProject.ext.archExtension
annotationProcessor rootProject.ext.archCompiler
implementation rootProject.ext.roomRuntime
annotationProcessor rootProject.ext.roomCompiler
implementation rootProject.ext.okhttp
implementation rootProject.ext.retrofit
implementation rootProject.ext.gsonConverter
//dagger
annotationProcessor rootProject.ext.daggerCompiler
implementation rootProject.ext.dagger
implementation rootProject.ext.daggerAndroid
implementation rootProject.ext.daggerAndroidSupport
annotationProcessor rootProject.ext.daggerAndroidProcessor
//ui
implementation rootProject.ext.picasso
}
\的build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
supportLibVersion = '25.3.1'
daggerVersion = '2.11'
retrofitVersion = '2.1.0'
gsonConverterVersion = '2.1.0'
okhttpVersion = '3.8.0'
picassoVersion = '2.5.2'
archVersion = '1.0.0-alpha1'
supportLibAppCompat = "com.android.support:appcompat-v7:$supportLibVersion"
supportLibDesign = "com.android.support:design:$supportLibVersion"
archRuntime = "android.arch.lifecycle:runtime:$archVersion"
archExtension = "android.arch.lifecycle:extensions:$archVersion"
archCompiler = "android.arch.lifecycle:compiler:$archVersion"
roomRuntime = "android.arch.persistence.room:runtime:$archVersion"
roomCompiler = "android.arch.persistence.room:compiler:$archVersion"
dagger = "com.google.dagger:dagger:$daggerVersion"
daggerCompiler = "com.google.dagger:dagger-compiler:$daggerVersion"
daggerAndroid = "com.google.dagger:dagger-android:$daggerVersion"
daggerAndroidSupport = "com.google.dagger:dagger-android-support:$daggerVersion"
daggerAndroidProcessor = "com.google.dagger:dagger-android-processor:$daggerVersion"
retrofit = "com.squareup.retrofit2:retrofit:$retrofitVersion"
gsonConverter = "com.squareup.retrofit2:converter-gson:$gsonConverterVersion"
okhttp = "com.squareup.okhttp3:okhttp:$okhttpVersion"
picasso = "com.squareup.picasso:picasso:$picassoVersion"
}
gradle这个\ gradle-wrapper.properties:
#Thu May 18 17:31:31 EEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-1-all.zip
有谁知道这个错误发生的原因?
答案 0 :(得分:30)
我必须将gradle-wrapper.properties
中的distributionUrl更改为distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
才能让构建再次运行。这似乎是一个类似的问题Gradle sync failed: Unable to find method。
答案 1 :(得分:1)
从外部资源导入项目时,将生成一些文件,因为其中包含特定于本地配置的信息,其中一个是gradle-wrapper.properties
,降级为较低版本并重建项目,错误应该消失
distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip
到
distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip
答案 2 :(得分:1)
更改gradle.wrapper.properties您的 distributionUrl = https://services.gradle.org/distributions/gradle-4.10.1-all.zip的值更改为此,android studio将为您自动更新gradle,应该没事
答案 3 :(得分:0)
看起来您无法解决testInstrumentation问题。你在使用facebook.screenshot api吗?如果是这样,你需要包含它。
否则,只需注释掉testInstrument部分,看看你是否可以在没有测试的情况下进行构建,如果你不关心它们的话。否则你需要修复它的依赖用法。
*评论出来 testInstrumentationRunner“android.support.test.runner.AndroidJUnitRunner”
这会导致在清单中创建一行,并且可能无法正确解析。
答案 4 :(得分:0)
对于android studio路径“文件夹项目/gradle/wrapper/gradle-wrapper.properties”文件更改URL值distributionUrl = https://services.gradle.org/distributions/gradle-4.10.1-all。 zip http://services.gradle.org/distributions/
中的相应版本(上一个)答案 5 :(得分:0)
如果删除 .gradle和.idea 文件后出现此错误,则发生此错误,因为Gradle文件不适用于该项目,并且Android Studio无法下载相同版本的Gradle依赖项。您可以切换到较低版本的Gradle choose from here,然后转到 gradle-wrapper-properties 文件并更改版本,在本例中,我将其从distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
更改为distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
。下载较旧版本的Gradle依赖项后,将出现Gradle更新对话框,提示您可以通过该对话框获取最新版本,在这种情况下为 5.1.1 。
答案 6 :(得分:0)
我通过添加classpath 'com.android.tools.build:gradle:3.2.1'
来解决此错误
在build.gradle项目中
buildscript {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
答案 7 :(得分:0)
在文件SampleProject/gradle/wrapper/gradle-wrapper.properties
更改
distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip
到
distributionUrl=https://services.gradle.org/distributions/gradle-4.6-all.zip
答案 8 :(得分:-1)
在AndroidStudio 3.5的以下行中正常工作
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip