【问题标题】:Gradle Project Sync Failed, KotlinGradle 项目同步失败,Kotlin
【发布时间】:2017-11-23 05:02:00
【问题描述】:

我正在使用测试版 Kotlin 和 Android-Studio 频道。更新到最新版本后,我遇到了一些 gradle 同步错误。

以下是我从事件日志中复制的日志:

Error:Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.0-rc-39.
Searched in the following locations:
    file:/home/yourpc/Android/android/gradle/m2repository/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.pom
    file:/home/yourpc/Android/android/gradle/m2repository/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.jar
    https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.pom
    https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.jar
    https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.pom
    https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.jar
Required by:
    project :

下面是 build.gradle

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

buildscript {
    ext.kotlin_version = '1.2.0-rc-39'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0-alpha04'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$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
}

下面是app build.gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.udebest.myapplication"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            postprocessing {
                removeUnusedCode false
                removeUnusedResources false
                obfuscate false
                optimizeCode false
                proguardFile 'proguard-rules.pro'
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

请问,有人对此有任何想法吗?我真的不知道我该如何解决这个问题?我找不到任何解决方案。

【问题讨论】:

    标签: android android-gradle-plugin kotlin


    【解决方案1】:

    buildscriptallprojects 中的repositories 更改为:

    {
        google()
        jcenter()
        mavenCentral()
        maven {
            url 'https://dl.bintray.com/kotlin/kotlin-dev/'
        }
    }
    

    这对我有用。

    【讨论】:

    • 我去寻找可以记录的地方。我发现的一件事是这篇博文末尾的注释:blog.jetbrains.com/kotlin/2017/09/kotlin-1-2-beta-is-out 关于需要为 kotlin 1.2 beta 添加存储库。该帖子中的回购是kotlin-1.2-eap,而不是kotlin-dev,但我认为两者都有包。
    【解决方案2】:

    首先,我通过工具 Kotlin 更新了 Kotlin 插件,配置了 kotlin 插件更新。

    之后,在App目录下,在build.Gradle文件中搜索:

    repositories {
             // You need to add the following repository to download the
            // new plugin.
            google()
                  }
    

    我添加了一个新的存储库

    maven { url 'C:/Program Files/Android/Android Studio/gradle/m2repository/'}
    

    这是通过我的资源所在的本地目录的路径。在此之后再次尝试同步

    【讨论】:

      【解决方案3】:

      改变并尝试

      classpath 'com.android.tools.build:gradle:3.1.0-alpha04'
      

      classpath 'com.android.tools.build:gradle:3.0.0'
      

      这可能是由于 gradle 的 alpha 版本。

      【讨论】:

      • 我已经尝试过了.. 但它仍然打印相同的错误日志。顺便说一句,你怎么知道你应该使用哪个 gradle 版本?大多数情况下,当 Android Studio 要求我更新更新的 gradle 版本或创建项目并为我选择它时,我会关注它。让我公会,这样我就可以选择最好的了。
      【解决方案4】:

      在 build.gradle(Project) 中使用以下版本的 kotlin

      kotlin_version = '1.1.4-3'
      dependencies {
          classpath 'com.android.tools.build:gradle:3.0.0'
          classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
      }
      

      在 build.gradle(Module) 中声明 kotlin 的依赖关系如下

      compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
      

      【讨论】:

        【解决方案5】:

        在 build.gradle 中检查您的 Kotlin 版本。 当版本是默认添加的 1.1.0 时,我遇到了同样的问题。 更改为最新版本 1.3.21 然后它工作正常。

        【讨论】:

          【解决方案6】:

          在安装了 Ray Eldath 的 react-native-image-picker 之后,该解决方案对我的 React Native(0.63) 有效,来自上述评论

          //in android.build.gradle
          
          {
              google()
              jcenter()
              mavenCentral()
              maven {
                       url 'https://dl.bintray.com/kotlin/kotlin- 
              dev/'
              }
          }
          

          【讨论】:

            【解决方案7】:

            首先关闭Android Studio,删除.gradle文件夹,然后再次打开Android Studio,大概是管理员身份 这将使它从一开始就同步,并解决问题。

            此问题已为我的一位同行解决。

            【讨论】:

              【解决方案8】:

              卸载 Kotlin 插件(Preferences > Plugins > Kotlin > Uninstall)并使用 IDE 自带的版本。

              【讨论】:

              • 当我将 Kotlin 版本降级到稳定版本时,它运行良好。但是如何安装一个测试版而不是稳定版来享受新功能呢?卸载测试版后,它就可以正常工作了。但是因为我想使用测试版,所以我尝试重新安装它,测试版不起作用。我只是想知道如何让一个测试版现在工作。你知不知道怎么?请帮忙。
              猜你喜欢
              • 2015-06-10
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2014-07-03
              • 2014-04-04
              相关资源
              最近更新 更多