Gradle Project Sync Failed, Kotlin

12,903

Solution 1

Change your repositories in buildscript and allprojects into:

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

This works for me.

Solution 2

First, I updated Kotlin plugin thru tool, Kotlin, configure kotlin plugin update.

After, in App directory, in build.Gradle file search:

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

I add a new repository

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

this is the path thru my local directory where the resources are. After this try again to sync

Share:
12,903
Nara Na
Author by

Nara Na

Updated on June 26, 2022

Comments

  • Nara Na
    Nara Na about 2 years

    I am using a beta Kotlin and Android-Studio channel. After update to the latest version i got some gradle sync error.

    Below are the log i copied from Event Log:

    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 :
    

    below is the 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
    }
    

    below is the 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'
    }
    

    Please, anyone has an idea about this? I don't really know how can I solve this? I could not find any solutions out there.

  • Nara Na
    Nara Na over 6 years
    it is working perfect when i downgrade Kotlin version to the stable one. But how about installing a beta version instead of stable one to enjoy new features? After uninstall the beta version, it just work fine. But because I wanted to use a beta one, then I try to reinstall it back and the beta one doesn't work. I just wonder how to make a beta one working now. Do you know how? please help.
  • Nara Na
    Nara Na over 6 years
    i have tried it.. but it still print the same error log. By the way, how do you know which gradle version should you use? Mostly i follow Android Studio when it asks me to update a newer gradle version or when creating project and it selected it for me. Let guild me so i can select the best one.
  • keturn
    keturn over 6 years
    I went looking for where this might be documented. The one thing I found was a note at the end of this blog post: blog.jetbrains.com/kotlin/2017/09/kotlin-1-2-beta-is-out about needing to add a repository for the kotlin 1.2 beta. The repo in that post is kotlin-1.2-eap, not kotlin-dev, but both have the packages, I think.