当前位置: 首页 > 知识库问答 >
问题:

android数据绑定单元测试错误无法解析数据绑定编译器选项。参数:

柯易安
2023-03-14

当我尝试为我的kotlin android项目设置单元测试时,我遇到了以下错误。以前有人遇到过这种问题吗?

这在官方的bug tracker上被标记为bug

    FAILURE: Build failed with an exception.
     * What went wrong: Execution failed for task ':app:compileDebugUnitTestJavaWithJavac'. > java.lang.RuntimeException: Failed to parse data binding compiler options. Params: kapt.annotations : /Users/trevor/Dev/Android/workspace/gitlab-example/app/build/tmp/kapt/debugUnitTest/wrappers/annotations.debugUnitTest.txt kapt.kotlin.generated : /Users/trevor/Dev/Android/workspace/gitlab-example/app/build/tmp/kapt/debugUnitTest/kotlinGenerated 
    * Try:
    Run with --info or --debug option to get more log output.

    * Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugUnitTestJavaWithJavac'.
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
            at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
            at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
            at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
            at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
            at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
            at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
            at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
            at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
            at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
            at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
            at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
            at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
            at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
            at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
            at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
            at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
            at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
            at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
            at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
            at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
            at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
            at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
            at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
            at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
            at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196)
            at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193)
            at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
            at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193)
            at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
            at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
            at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
            at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
            at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
            at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
            at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
            at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
            at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
            at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
            at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
            at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
            at org.gradle.util.Swapper.swap(Swapper.java:38)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
            at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
            at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
            at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
    Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Failed to parse data binding compiler options. Params:
    kapt.annotations : /Users/trevor/Dev/Android/workspace/gitlab-example/app/build/tmp/kapt/debugUnitTest/wrappers/annotations.debugUnitTest.txt
    kapt.kotlin.generated : /Users/trevor/Dev/Android/workspace/gitlab-example/app/build/tmp/kapt/debugUnitTest/kotlinGenerated
            at com.sun.tools.javac.main.Main.compile(Main.java:553)
            at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
            at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
            at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:46)
            at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:33)
            at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:104)
            at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:53)
            at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38)
            at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35)
            at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
            at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:206)
            at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:187)
            at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:130)
            at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:49)
            at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
            at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:163)
            at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
            at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
            ... 70 more
    Caused by: java.lang.RuntimeException: Failed to parse data binding compiler options. Params:
    kapt.annotations : /Users/trevor/Dev/Android/workspace/gitlab-example/app/build/tmp/kapt/debugUnitTest/wrappers/annotations.debugUnitTest.txt
    kapt.kotlin.generated : /Users/trevor/Dev/Android/workspace/gitlab-example/app/build/tmp/kapt/debugUnitTest/kotlinGenerated
            at android.databinding.annotationprocessor.ProcessDataBinding.readArguments(ProcessDataBinding.java:159)
            at android.databinding.annotationprocessor.ProcessDataBinding.process(ProcessDataBinding.java:65)
            at org.jetbrains.kotlin.annotation.AnnotationProcessorWrapper.process(AnnotationProcessorWrapper.kt:129)
            at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
            at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
            at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
            at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
            at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
            at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
            at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
            at com.sun.tools.javac.main.Main.compile(Main.java:523)
            ... 89 more
    Caused by: java.lang.NumberFormatException: null
            at android.databinding.tool.DataBindingCompilerArgs.readFromOptions(DataBindingCompilerArgs.java:92)
            at android.databinding.annotationprocessor.ProcessDataBinding.readArguments(ProcessDataBinding.java:152)
            ... 99 more


    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'

    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"
        defaultConfig {
            applicationId "com.example.abce"
            minSdkVersion 15
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }

        dataBinding {
            enabled = true
        }
    }

    kapt {
        generateStubs = true
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:25.2.0'
        compile 'com.android.support.constraint:constraint-layout:1.0.1'

        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
        kapt "com.android.databinding:compiler:2.3.0"

        testCompile 'junit:junit:4.12'
        testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
    }
    repositories {
        mavenCentral()
    }


    buildscript {
        ext.kotlin_version = '1.1.0'
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

    allprojects {
        repositories {
            jcenter()
        }
    }

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


    import org.junit.Assert.assertEquals
    import org.junit.Test

    /**
     * Example local unit test, which will execute on the development machine (host).

     * @see [Testing documentation](http://d.android.com/tools/testing)
     */
    class ExampleUnitTest {
        @Test
        @Throws(Exception::class)
        fun addition_isCorrect() {
            assertEquals(4, (2 + 2).toLong())
        }

        @Test
        fun additon_isNotCorrect() {
            assertEquals(4, (2 + 3))
        }
    }

共有1个答案

西门磊
2023-03-14

您需要将apply plugin:'kotlin-kapt'添加到您的应用程序分级文件中。本文说明(新实验注释处理)https://blog.jetbrains.com/kotlin/2016/09/kotlin-1-0-4-is-here/#sthash.y5nthdyw.dpuf

 类似资料:
  • 我的布局名称是。我还看到了Android-DataBinding-绑定类将如何和何时生成?但这帮不了我。

  • 如果在编译过程中出现任何错误,则不会生成数据绑定类-因此,我会遇到大量类似这样的错误: 问题是,编译错误与数据绑定根本没有关系,因此我不知道究竟是什么导致了它——我必须手动挖掘文件以找到问题所在。 在上面的示例中,我只是从需要它的构造函数中省略了。在这种情况下,很高兴看到Dagger的错误消息,这样我就可以立即找到它,而不必深入所有项目类手动查找它。 任何帮助都将不胜感激! 两个Android S

  • 我的要求是对输入文件中给出的数据运行测试。为了实现,我正在使用 请帮助确定我做错了什么。

  • 我有一个正在运行的Android Studio项目,也通过USB安装在我的智能手机上,它是一个简单的基本计算器。现在我必须为我所教的课程重写代码,但Android Studio拒绝此导入 该应用程序使用我在模块中启用的数据绑定:应用程序并重新同步所有内容。 旧的项目工作,新的没有,相同的代码,因为这个进口被拒绝。

  • 我想知道以下内容之间有什么区别: 与 有任何性能差异吗? 每个的首选用例是什么? 任何其他信息都将不胜感激! 谢谢!

  • 在使用新的数据绑定api时,我发现无法绑定到“style”属性。编译器抱怨找不到样式。然而,如果我简单地将样式设置为原样,它会发现它很好。例如: 不工作: 作品: 错误: 错误:任务“:app:compiledBugJavaWithJavaC”的执行失败。 JAVAlang.RuntimeException:发现数据绑定错误。****/数据绑定错误****msg:标识符必须具有XML文件中的用户定