Gradle构建失败,并显示以下消息:TaskDependencyResolveException:无法确定任务':compileDebugKotlin'的依赖项

时间:2019-01-22 09:50:33

标签: java android gradle kotlin android-gradle

我已将 Android Studio 更新为 3.3 ,现在我无法构建自己的现有项目之一,我尝试了无效/重启,还检查了{{1} } gradle版本是最新更新:

gradle-wrapper.properties

这是我的distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

build.gradle

当我尝试构建项目apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'realm-android' apply plugin: 'kotlin-kapt' buildscript { ext.kotlin_version = '1.3.11' repositories { google() jcenter() mavenCentral() maven { url 'https://maven.google.com' } } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.android.tools.build:gradle:3.3.0' classpath 'com.google.gms:google-services:4.2.0' classpath "io.realm:realm-gradle-plugin:3.1.3" } } repositories { google() jcenter() mavenCentral() maven { url "https://jitpack.io" } maven { url 'https://maven.google.com' } } androidExtensions { experimental = true } android { compileSdkVersion 22 buildToolsVersion '28.0.3' defaultConfig { applicationId "my.package.name" minSdkVersion 16 targetSdkVersion 22 versionCode 1 versionName "1.0.0" multiDexEnabled true vectorDrawables.useSupportLibrary = true ndk { abiFilters "armeabi-v7a", "x86", "armeabi", "mips" } } lintOptions { checkReleaseBuilds false abortOnError false } sourceSets { main { manifest.srcFile 'AndroidManifest.xml' .... res.srcDirs = ['res'] assets.srcDirs = ['assets'] jniLibs.srcDir 'libs' } androidTest.setRoot('tests') debug.setRoot('build-types/debug') release.setRoot('build-types/release') } buildTypes { } } ext { supportLibraryVersion = '22.2.0' googleServicesVersion = '17.3.4' retrofitVersion = '2.3.0' } dependencies { implementation fileTree(include: '*.jar', dir: 'libs') implementation 'com.android.support.constraint:constraint-layout:1.1.3' androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) [ 'cardview-v7', 'design' ].each { implementation "com.android.support:$it:$supportLibraryVersion" } implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'org.jetbrains.anko:anko-sdk23:0.9.1' implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.android.support:multidex:1.0.3' implementation 'com.squareup:otto:1.3.8' implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion" implementation 'com.squareup.okhttp3:okhttp:3.11.0' implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1' implementation "com.google.firebase:firebase-messaging:$googleServicesVersion" } apply plugin: 'com.google.gms.google-services' 时出现错误

preDebugBuild

Java编译器:(1个错误)

org.gradle.api.UncheckedIOException: Failed to capture fingerprint of input files for task ':preDebugBuild' property 'compileManifests' during up-to-date check.

如果我运行Caused by: java.lang.ArrayIndexOutOfBoundsException: 1

assembleDebug

如果也运行* Exception is: org.gradle.api.internal.tasks.TaskDependencyResolveException: Could not determine the dependencies of task ':compileDebugKotlin.' ... Caused by: java.lang.ArrayIndexOutOfBoundsException: 1 Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0. Use '--warning-mode all' to show the individual deprecation warnings.

./gradlew build -Dorg.gradle.warning.mode=all

如何解决此问题?这是在Android Studio更新后发生的。

更新 The project name 'myapp-android production' contains at least one of the following characters: [ , /, \, :, <, >, ", ?, *, |]. This has been deprecated and is scheduled to be removed in Gradle 5.0. Set the 'rootProject.name' or adjust the 'include' statement (see https://docs.gradle.org/4.10.1/dsl/org.gradle.api.initialization.Settings.html#org.gradle.api.initialization.Settings:include(java.lang.String[]) for more details) Could not resolve compiler classpath. Check if Kotlin Gradle plugin repository is configured in root project 'myapp-android production' FAILURE: Build failed with an exception. * What went wrong: Could not determine the dependencies of task ':compileReleaseKotlin'. 的结果

./gradlew --stacktrace assembleDebug

3 个答案:

答案 0 :(得分:3)

好吧,如果此错误是在升级到Android Studio 3.3之后立即开始的,那么我建议您应该执行以下步骤... 但是首先请确保备份整个项目。

  • 在Android Studio中,转到“文件”>“项目结构”,然后取消选中“使用嵌入式JDK”,然后单击“确定”
  • 转到“计算机设置”(系统设置)(win +暂停键),然后转到“高级系统设置”>“环境变量”。如果JAVA_HOME不存在,则将其添加并设置到已安装的JDK的路径。
  • 由于我找不到在以某种方式升级到android studio 3.3设置的项目中修改jdk路径的直接方法,所以我做了以下(最后一步)
    但是请确保在此之前进行备份。 为了确保我要引导的位置进入项目视图,我删除了“ .grade”,“。idea”。然后重建项目,它现在应该可以正常使用!!!

就最新而言,将其更改为5.2.1是
https://services.gradle.org/distributions/gradle-5.2.1-all.zip

如果您对kotlin插件有疑问,请参阅
中的“定位Android”部分 https://kotlinlang.org/docs/reference/using-gradle.html

答案 1 :(得分:2)

将google服务的版本降级到4.1.0,该错误将消失。问题似乎出在4.2.0版本中。

答案 2 :(得分:0)

在Android Studio终端上运行./gradlew assembleDebug命令已解决了我的问题。

相关问题