Gradle Project Sync失败,Kotlin

时间:2017-11-23 05:02:01

标签: android android-gradle kotlin

我正在使用测试版Kotlin和Android-Studio频道。更新到最新版本后,我得到了一些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'
}

拜托,有人对此有所了解吗?我真的不知道如何解决这个问题?我找不到任何解决方案。

8 个答案:

答案 0 :(得分:4)

repositoriesbuildscript中的allprojects更改为:

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

这适合我。

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

更改并尝试

this.dtOptions = {
        ajax: {
            url: '/api/users/get_users'
            , dataSrc: 'data'
            , type: "POST"
            , data: {test: 1}
            , headers: {
                //                    Authorization: 'Bearer ' + localStorage.getItem('token')
                Authorization: 'Bearer awdsafsdvaefaa5s4das5d4sa4sadd58a7sd45sa4dsad5a4d5sadasd54sad54d54d5sa4dsa5d4sad54sad5d5sa' + localStorage.getItem('token')
            }
        },
        pagingType: 'full_numbers',
        pageLength: 10,
        serverSide: true,
        processing: true,
        columns: [
            {
                title: '',
                defaultContent: '<input type="checkbox">'
            },
            {
                title: 'ID',
                data: 'id'
            },
            {
                title: 'First name',
                data: 'firstname'
            },
            {
                title: 'Last name',
                data: 'lastname'
            },
            {
                title: 'Status',
                defaultContent: '<button class="btn btn-default btn-xs edit-country-btn">Active</button>'
            },
            {
                title: 'Actions',
                orderable: false,
                searchable: false,
                defaultContent: '<button class="btn btn-default btn-xs edit-country-btn">Edit</button>'
            },
            {
                title: 'Extra',
                orderable: false,
                searchable: false,
                data: function (full, data, row, meta)
                {
                    if (!self.temp)
                    {
                       //dynamic ngModel binding 
                        return '<button [(ngModel)]="dynamic_model[full.id]" [disabled]="true" class="btn btn-default btn-xs edit-country-btn">EXTRA</button>';
                    }
                    else
                    {
                        return '---';
                    }
                }
            },
            {
                title: 'Extra2',
                orderable: false,
                searchable: false,
                defaultContent: ''
            },
            {
                title: 'Extra3',
                orderable: false,
                searchable: false,
                render: function (data, type, row, meta)
                {
                    if (!self.temp)
                    {
                        return '<button [disabled]="true" class="btn btn-default btn-xs edit-country-btn">EXTRA</button>';
                    }
                    else
                    {
                        return '---';
                    }
                }
            }
        ],
        rowCallback: (row: Node, data: any[] | Object, index: number) =>
        {
            const self = this;
            var str = '---';
            var str1 = '<button [disabled]="true" class="btn btn-default btn-xs edit-country-btn">TEST</button>';

            //$('td:nth-child(1) input', row).bind('model', this.checkArr[0]);

            $('td:nth-child(5) button', row).bind('click', () =>
            {
                self.test(data);
            });

            $('td:nth-child(8)', row).append(str1);

            return row;
        }
    };

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

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

答案 4 :(得分:0)

在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 :(得分:0)

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

答案 6 :(得分:0)

在上面的评论中,由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 :(得分:0)

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

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