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

标签 android android-studio kotlin android-gradle-plugin project

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

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

为什么会这样?

我的 gradle 文件是:

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

项目级gradle:

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

我认为,android studio 本身有问题,因为我试图创建新项目,但我也遇到了同样的错误。

最佳答案

首先,尝试将您的 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 插件会有帮助

转到:文件 -> 设置 -> 插件 更新 kotlin,然后重新启动。

关于android - 由于 kotlin,Android 中的 Gradle 同步失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52754319/

相关文章:

android - 更改 ProgressDialog 的样式

c# - 如何在Kotlin中创建等效于C#的新字符串

android - Android Studio中这两个Gradle是什么意思?

android-studio - 在 Tensorboard 上分析 tensorflow 图或 .pb 文件

java - 使用 GSON 序列化时出现 "declares multiple JSON fields named"错误

Kotlin 自定义属性数据绑定(bind)

android - Room allowMainThreadQueries 与 Kotlin 协程

android - 在 Android 模拟器上打开网络浏览器

android - 如果从主线程执行方法,如何抛出异常

android - 在 android 中使用共享首选项保存数据