Android:尝试使用数据绑定时Kotlin执行失败

时间:2017-11-11 08:25:12

标签: android data-binding kotlin

我正在尝试使用新的Android数据绑定库绑定视图。我尝试运行该应用程序并收到以下错误:

  

错误:任务':app:kaptDebugKotlin'执行失败。   内部编译器错误。有关更多详细信息,请参阅日志

以下是 MainActivity.kt

import android.databinding.DataBindingUtil
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import app.android.androidtexteditor.databinding.ActivityMainBinding
import app.android.androidtexteditor.models.TextEditor


class MainActivity : AppCompatActivity() {

lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    binding = DataBindingUtil.setContentView(this, R.layout.activity_main)

    var textEditor = TextEditor("content")
    binding.textEditor = textEditor
    binding.executePendingBindings()

 }
}

以下是 TextEditor.kt

class TextEditor(var content: String?)

以下是 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    >

    <data>
        <variable
            name="textEditor"
            type="app.android.androidtexteditor.models.TextEditor"/>
    </data>

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        >
            <jp.wasabeef.richeditor.RichEditor
                android:id="@+id/text_editor_content"
                android:text="@{textEditor.content}"
                android:layout_width="327dp"
                android:layout_height="478dp"
                android:layout_marginBottom="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:padding="20dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                />

    </android.support.constraint.ConstraintLayout>

</layout>

注意:从XML中移除android:text="@{textEditor.content}"时,应用程序会正常运行。

修改

以下是日志:

  

2017-11-11 14:13:24,608 [thread 118] INFO -   s.plugins.gradle.GradleManager - 指示gradle使用java   /私有的/ var /文件夹/ TW / _9p_vd716zz1mr4lkp_69h880000gn / T / AppTranslocation / 3BF8BBE1-C94A-4F85-9008-1FC1B3EE13FB / d / Android的   Studio 3.1 Preview.app/Contents/jre/jdk/Contents/Home 2017-11-11   14:13:24,683 [thread 118] INFO - oject.common.GradleInitScripts -   init脚本文件sync.local.repo内容&#34; allprojects {\ n   buildscript {\ n repositories {\ n maven {url   &#39; /私有的/ var /文件夹/ TW / _9p_vd716zz1mr4lkp_69h880000gn / T / AppTranslocation / 3BF8BBE1-C94A-4F85-9008-1FC1B3EE13FB / d / Android的   Studio 3.1 Preview.app/Contents/gradle/m2repository'}\n} \ n} \ n   存储库{\ n maven {url   &#39; /私有的/ var /文件夹/ TW / _9p_vd716zz1mr4lkp_69h880000gn / T / AppTranslocation / 3BF8BBE1-C94A-4F85-9008-1FC1B3EE13FB / d / Android的   Studio 3.1 Preview.app/Contents/gradle/m2repository'}\n} \ n} \ n&#34;   2017-11-11 14:13:24,684 [thread 118] INFO -   ild.invoker.GradleBuildInvoker - 构建命令行选项:   [--configure-on-demand,-Pandroid.injected.invoked.from.ide = true,   --init-script,/private/var/folders/tw/_9p_vd716zz1mr4lkp_69h880000gn/T/sync.local.repo2551.gradle]   2017-11-11 1

     

4:13:24,684 [thread 118] INFO - xecution.GradleExecutionHelper -   将命令行参数传递给Gradle Tooling API: - configure-on-demand   -Pandroid.injected.invoked.from.ide = true --init-script /private/var/folders/tw/_9p_vd716zz1mr4lkp_69h880000gn/T/sync.local.repo2551.gradle   2017-11-11 14:13:24,921 [主题100]信息 -   idea.project.IndexingSuspender - 索引已挂起(上下文:Gradle   Build)2017-11-11 14:13:26,683 [thread 100] INFO -   idea.project.IndexingSuspender - 发布索引(context:Gradle   Build)2017-11-11 14:13:26,686 [thread 116] INFO -   roid.sdk.MessageBuildingSdkLog -   com.android.ide.common.blame.Message(com.android.ide.common.blame.Message $类,   java.lang.String,java.lang.String,   com.google.common.collect.ImmutableList)   java.lang.NoSuchMethodException:   com.android.ide.common.blame.Message(com.android.ide.common.blame.Message $类,   java.lang.String,java.lang.String,   com.google.common.collect.ImmutableList)at   j

的java.lang.Class.getConstructor0(Class.java:3082)      

ava.lang.Class.getConstructor(Class.java:1825)at   org.jetbrains.kotlin.android.KotlinOutputParserHelper $ simpleMessageConstructor $ 2.invoke(KotlinOutputParserHelper.kt:171)     在   org.jetbrains.kotlin.android.KotlinOutputParserHelper $ simpleMessageConstructor $ 2.invoke(KotlinOutputParserHelper.kt:143)     在kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:130)at   org.jetbrains.kotlin.android.KotlinOutputParserHelper.getSimpleMessageConstructor(KotlinOutputParserHelper.kt)     在   org.jetbrains.kotlin.android.KotlinOutputParserHelper.createNewMessage(KotlinOutputParserHelper.kt:272)     在   org.jetbrains.kotlin.android.KotlinOutputParserHelper.createMessage(KotlinOutputParserHelper.kt:250)     在   org.jetbrains.kotlin.android.KotlinOutputParserHelper.createMessage $默认(KotlinOutputParserHelper.kt:244)     在   org.jetbrains.kotlin.android.KotlinOutputParserHelperKt.parse(KotlinOutputParserHelper.kt:41)     在   org.jetbrains.kotlin.android.KotlinOutputParser.parse(KotlinOutputParser.java:28)     在   com.android.ide.common.blame.parser.ToolOutputParser.parseToolOutput(ToolOutputParser.java:86)     在   com.android.tools.idea.gradle.output.parser.BuildOutputParser.parseGradleOutput(BuildOutputParser.java:43)     在   com.android.tools.idea.gradle.project.build.invoker.GradleTasksExecutorImpl.lambda $ collectMessages $ 5(GradleTasksExecutorImpl.java:487)     在   com.intellij.openapi.application.impl.ApplicationImpl $ 2.run(ApplicationImpl.java:334)     在   java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)     在java.util.concurrent.FutureTask.run(FutureTask.java:266)at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)2017-11-11 14:13:26,687   [thread 116] INFO - roid.sdk.MessageBuildingSdkLog - 来自的例外   KotlinOutputParser 2017-11-11 14:13:26,817 [e-1012-b01]信息 -   ild.invoker.GradleBuildInvoker - Gradle构建完成,出现1个错误   在2s 79ms 2017-11-11 14:13:26,868 [e-1012-b01]信息 -   pl.ProjectRootManagerComponent - 项目根已更改   2017-11-11 14:13:27,145 [主题119]信息 -   .diagnostic.PerformanceWatcher - 推送属性需要1ms;一般   响应性:好的; EDT响应:好2017-11-11 14:13:27,184   [thread 119] INFO - .diagnostic.PerformanceWatcher - 可索引文件   迭代耗时38ms;一般回应:好的; EDT响应能力:   ok 2017-11-11 14:13:28,217 [J pool 1/4]警告 -   hes.resolve.KotlinCacheService - 找不到正确的模块   信息。原因:分析类型的元素   com.android.tools.idea.databinding.LightGeneratedComponentClass with   不包含文件文字:null 2017-11-11 14:13:28,217 [J pool 1/4]
  WARN - .resolve.jvm.JvmAnalyzerFacade - Java引用null   LibraryInfo(库名称= com.android.databinding:文库-1.3.1)   引用的类是:JavaClassImpl:DATA绑定组件类
  2017-11-11 14:13:28,217 [J pool 1/4]警告 -   hes.resolve.KotlinCacheService - 找不到正确的模块   信息。原因:分析类型的元素   com.android.tools.idea.databinding.LightGeneratedComponentClass with   不包含文件文字:null 2017-11-11 14:13:28,217 [J pool 1/4]
  WARN - .resolve.jvm.JvmAnalyzerFacade - Java引用null   LibraryInfo(库名称= com.android.databinding:文库-1.3.1)   引用的类是:JavaClassImpl:DATA绑定组件类

1 个答案:

答案 0 :(得分:0)

经过数小时的研究,我发现我使用的第三方库是问题所在:RichEditor。它不支持android: text