代码之家  ›  专栏  ›  技术社区  ›  Minion

由于kotlin,android中的Gradle同步失败

  •  -1
  • Minion  · 技术社区  · 6 年前

    我没有在我的程序中使用kotlin,除非我将目标版本从26更新到28,否则它工作正常。我对kotlin一点也不了解。每当我尝试同步gradle文件时,它都会给出一个错误:

    org.jetbrains.kotlin.gradle.KotlinGradleModel.getImplements()Ljava/util/List;
    

    为什么会这样?

        apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.example.pr20020897.dms"
            minSdkVersion 21
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        testImplementation 'junit:junit:4.12'
        implementation 'com.android.support:design:28.0.0-alpha1'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    }
    

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
    
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.4'
    
    
            // 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
    }
    

    我认为androidstudio本身有问题,因为我试图创建一个新的项目,但在这方面我也得到了同样的错误。

    1 回复  |  直到 6 年前
        1
  •  1
  •   ʍѳђઽ૯ท    6 年前

    首先,尝试将你的gradle更新为:

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

    在依赖项中,使用稳定版本:

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    

    既然你说你不使用kotlin,更新kotlin插件会有帮助

    File -> Settings -> Plugins 更新kotlin,然后重新启动。