Error when building on new Android Studio 3.1

2020-04-04 09:14发布

问题:

I updated Android Studio to 3.1 stable version and get this error, when try to build project. At first there were problems with DataBinding, I fixed them, then I found this issue.

org.gradle.api.GradleException: Compilation error. See log for more details
at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:8)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.processCompilerExitCode(Tasks.kt:415)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:389)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:251)
at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute(Tasks.kt:215)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)

[this is not full version of error logs]

Does anybody find solution?

回答1:

This recommendations depends, how much complicated your project(these recommendations can be not usefull):

  • Update Kotlin plugin to last version

  • Remove

    kapt { generateStubs = true }

  • If you use databinding, add to gradle.properties this line android.databinding.enableV2=true

  • update gradle
  • update build tools

Thanks for my coworkers to find these facts



回答2:

Update your kotlin version "1.2.31" add following dependencies in app level gradle file

compile "org.jetbrains.kotlin:kotlin-stdlib"

android {
  ...

  sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
  }
}

It may help to you :)



回答3:

Just checkout this project and see build.gradle files. I just updated this project for Android Studio 3.1 and met the same error as yours, but everything works well now after some changes in build.gradle.

https://github.com/thierryxing/Douban

The main updates:

apply plugin: 'kotlin-kapt'

dependencies {
    kapt "com.android.databinding:compiler:$gradle_version"
}