解决A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask

The error when building the Kotlin project is as follows:

Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)
  1. First check if there are other error messages:
    for example:
错误: cannot generate view binders java.lang.NullPointerException
  	at android.databinding.tool.store.SetterStore.calculateConversionPriority(SetterStore.java:995)
  	at android.databinding.tool.store.SetterStore.isBetterParameter(SetterStore.java:890)
  	at android.databinding.tool.store.SetterStore.getBestSetter(SetterStore.java:750)
  	at android.databinding.tool.store.SetterStore.getSetterCall(SetterStore.java:572)
  	at android.databinding.tool.Binding.getListenerParameter(Binding.java:175)
  	at android.databinding.tool.Binding.resolveCallbackParams(Binding.java:77)
  	at android.databinding.tool.BindingTarget.resolveCallbackParams(BindingTarget.java:179)
  	at android.databinding.tool.LayoutBinder.<init>(LayoutBinder.java:142)
  	at android.databinding.tool.DataBinder.<init>(DataBinder.java:61)
  	at android.databinding.tool.CompilerChef.ensureDataBinder(CompilerChef.java:118)
  	at android.databinding.tool.CompilerChef.sealModels(CompilerChef.java:370)

This means there is a problem with ViewDataBinding. Check the XML file for any reference errors.

2. After eliminating problems at the code level and xml level, consider that this problem is mostly caused by version mismatch. Generally, it can be solved by following the following steps:

  • Does the Android Gradle plugin version match the required Gradle version?

The specific version corresponds to the address. The gradle plug-in version can be viewed in the
root directory. The gradle version can be viewed inbuild.gradlebuildscript{}
gradle/wrapper/gradle-wrapper.properties

  • Is the Android kotlin plugin version the same as the required Kotlin version?

The kotlin plug-in version can be viewed build.gradlein the root directory. The kotlin version of AS can be viewed inbuildscript{}
File | Settings | Languages & Frameworks | Kotlin

  • Is Gradle JDK correct?

File | Settings | Build, Execution, Deployment | Build Tools | GradleGradle JDKChoose the appropriate version fromEmbedded JDK

  • Do the versions of the third-party and kotlin plug-ins match?

For example
Kotlin-Version = 1.6.0 => Room-Version = 2.4.2

Guess you like

Origin blog.csdn.net/jxq1994/article/details/129880109