无法构建Kotlin项目:无法解析所有文件进行配置

时间:2018-09-08 13:59:57

标签: android android-studio kotlin kotlin-android-extensions

我正在尝试在Android Studio中首次使用Kotlin。我更新了Android Studio,但是当我尝试构建项目时,收到了错误消息 在下面发布。我试图通过遵循一些答案来解决它,但他们无法解决问题。

我试图通过将以下行添加到依赖项来解决此问题:

        classpath "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

但无法解决。

请查看构建文件,请让我知道如何解决

构建错误

org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration 
':classpath'.
Cause 1: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve org.jetbrains.kotlin:kotlin-reflect:1.2.61.

分级项目

buildscript {
ext.kotlin_version = '1.1.1'
repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    google()
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

分级应用

apply plugin: 'com.android.application'

android {
compileSdkVersion 26

defaultConfig {
    applicationId "com.example.pc_amr.snakegame_01.app"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
}

buildTypes {
   release {
       minifyEnabled false
       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
   }
}

}

dependencies {
implementation project(':feature')
implementation project(':base')
}

更新

after adding that line to gradle.app:
    apply plugin: 'com.android.application'
i received the following error:

Unable to find method 'com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()Ljava/util/List;'.
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.

please note that, 
    ext.kotlin_version = '1.1.1'
and kotlin version in Android Studio is:
    version 1.2.61

2 个答案:

答案 0 :(得分:0)

在build.gradle(app)顶部添加

apply plugin: 'kotlin-android'

并在项目gradle中设置ext.kotlin_version = '1.2.61'

答案 1 :(得分:0)

我设法通过将kotlin版本设置为来回答问题:

    ext.kotlin_version = '1.2.60'