NoSuchMethodError使用Kotlin和新的Android数据绑定

时间:2015-06-24 00:36:07

标签: android kotlin

尝试使用kotlin在项目中使用新的Android数据绑定(https://developer.android.com/tools/data-binding/guide.html),但在处理布局资源时失败:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':android-app:dataBindingLayoutsProcessDebugResources'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
Caused by: java.lang.NoSuchMethodError: kotlin.KotlinPackage.startsWith(Ljava/lang/String;Ljava/lang/String;)Z
    at android.databinding.tool.util.XmlEditor.expressionAttributes(XmlEditor.kt:68)
    at android.databinding.tool.util.XmlEditor.hasExpressionAttributes(XmlEditor.kt:59)
    at android.databinding.tool.util.XmlEditor.recurseReplace(XmlEditor.kt:199)
    at android.databinding.tool.util.XmlEditor.strip(XmlEditor.kt:127)
    at android.databinding.tool.store.LayoutFileParser.stripBindingTags(LayoutFileParser.java:260)
    at android.databinding.tool.store.LayoutFileParser.stripFileAndGetOriginal(LayoutFileParser.java:298)
    at android.databinding.tool.store.LayoutFileParser.parseXml(LayoutFileParser.java:70)
    at android.databinding.tool.LayoutXmlProcessor.processResources(LayoutXmlProcessor.java:102)
    at android.databinding.tool.DataBindingProcessLayoutsTask.doIt(DataBindingProcessLayoutsTask.kt:31)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:218)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:579)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:562)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    ... 13 more

1 个答案:

答案 0 :(得分:0)

我已经用Kotlin here

重新写了Blog for Data Binding android

使用Classpath

classpath 'com.android.tools.build:gradle:3.0.0-beta2'

<强>依赖

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
    ...
    dataBinding {
        enabled = true
    }
}

dependencies {
    ......
    kapt 'com.android.databinding:compiler:2.3.1'
}

了解更多详情,请查看this post