首页 文章

Gradle Project Sync失败,Kotlin

提问于
浏览
3

我正在使用beta Kotlin和Android-Studio Channels . 更新到最新版本后,我得到了一些gradle sync错误 .

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

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'
}

请问,有人对此有所了解吗?我真的不知道怎么解决这个问题?我找不到任何解决方案 .

5 回答

  • 0

    buildscriptallprojects 中的 repositories 更改为:

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

    这适合我 .

  • 0

    首先,我通过工具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/'}
    

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

  • 0

    卸载Kotlin插件(首选项>插件> Kotlin>卸载)并使用IDE附带的版本 .

  • 4

    改变并尝试

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

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

    这可能是由于gradle的alpha释放 .

  • 1

    在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"
    

相关问题