AndroidStudio无法同步Gradle文件

时间:2019-03-05 23:52:55

标签: android gradle kotlin kapt

最近,AndroidStudio停止为我工作。

如果我同步到gradle文件,则会出现此错误:

成绩同步失败:org / jetbrains / kotlin / kapt / idea / KaptGradleModelorg / jetbrains / kotlin / kapt / idea / KaptGradleModel

日志:

2019-03-05 14:32:47,370 [d thread 7]   WARN - ect.sync.idea.ProjectSetUpTask - java.lang.NoClassDefFoundError: org/jetbrains/kotlin/kapt/idea/KaptGradleModel
    at com.android.tools.idea.gradle.project.sync.idea.AndroidGradleProjectResolver.populateKaptKotlinGeneratedSourceDir(AndroidGradleProjectResolver.java:359)
    at com.android.tools.idea.gradle.project.sync.idea.AndroidGradleProjectResolver.populateModuleContentRoots(AndroidGradleProjectResolver.java:250)
    at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
    at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
    at org.jetbrains.plugins.gradle.service.project.TracedProjectResolverExtension.populateModuleContentRoots(TracedProjectResolverExtension.java:62)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.doResolveProjectInfo(GradleProjectResolver.java:383)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.access$100(GradleProjectResolver.java:76)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:879)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:863)
    at org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper.execute(GradleExecutionHelper.java:209)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:141)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:76)
    at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.lambda$resolveProjectInfo$0(RemoteExternalSystemProjectResolverImpl.java:37)
    at com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:58)
    at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.resolveProjectInfo(RemoteExternalSystemProjectResolverImpl.java:37)
    at com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:45)
    at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:100)
    at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:163)
    at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:149)
    at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3.execute(ExternalSystemUtil.java:573)
    at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$5.run(ExternalSystemUtil.java:678)
    at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:736)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:157)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:144)
    at com.intellij.openapi.progress.impl.CoreProgressManager$4.run(CoreProgressManager.java:395)
    at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:314)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

2019-03-05 14:32:47,370 [d thread 7]   WARN - ect.sync.idea.ProjectSetUpTask - org/jetbrains/kotlin/kapt/idea/KaptGradleModelorg/jetbrains/kotlin/kapt/idea/KaptGradleModel 
2019-03-05 14:32:47,370 [d thread 7]   INFO - e.project.sync.GradleSyncState - Gradle sync failed: org/jetbrains/kotlin/kapt/idea/KaptGradleModelorg/jetbrains/kotlin/kapt/idea/KaptGradleModel

Google搜索此错误时,人们提到要重新安装Kotlin插件。

这是问题:我从未安装过Kotlin插件。我不使用Kotlin,仅使用NDK和Java。

这一直很好。

AndroidStudio最近是否对Kotlin插件添加了要求?我现在被迫安装Kotlin吗?

更新

$ rm -rf ~/.gradle解决方案没有帮助。

菜单选项 使缓存无效/重新启动 没有帮助。

相关问题(升级到Gradle 5.2.1 )提供的solution无济于事。

操作系统:Ubuntu LTS

AndroidStudio版本:3.3.2

顶级gradle文件:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用的gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    lintOptions {
        checkReleaseBuilds false
    }
    defaultConfig {
        applicationId "com.steenriver.armor"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 134
        versionName "1.34"
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86'
        }
        externalNativeBuild {
            cmake {
                cFlags "-DCP_USE_DOUBLES=0 -DCP_USE_CGTYPES=0"
                cppFlags "-std=c++11 -DANDROID=1 -DPLAY=1 -DUSEES3=1 -DLOGTAG=armor -DCP_USE_DOUBLES=0 -DCP_USE_CGTYPES=0 -DAPPVER=$versionName"
                arguments "-DCMAKE_VERBOSE_MAKEFILE=0", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_ARM_MODE=arm"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            useProguard false
        }
        debug {
            externalNativeBuild {
                cmake {
                    cppFlags += "-DDEBUG"
                }
            }
        }
    }
    externalNativeBuild {
        cmake {
            path '../../Android/jni/CMakeLists.txt'
        }
    }
}


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testImplementation 'junit:junit:4.12'
    api 'com.android.support:support-v4:28.0.0'
    api 'com.android.support:appcompat-v7:28.0.0'

    api 'com.google.android.gms:play-services-auth:16.0.1'
    api 'com.google.android.gms:play-services-nearby:16.0.0'
    api 'com.google.android.gms:play-services-games:16.0.0'
    api 'com.android.billingclient:billing:1.1'
}

1 个答案:

答案 0 :(得分:3)

我已经尝试了很多方法,但是能够使该错误消失的唯一方法是启用Kotlin插件

settings

我觉得很奇怪,因为:

  • 以前没有Kotlin插件就可以正常工作。
  • 我在任何地方都不使用任何Kotlin代码。只是Java,C和C ++。

最近,我怀疑Android Studio在某个地方对Kotlin产生了虚假依赖。这是不幸的。我不明白为什么需要此插件。