当构建失败并出现 "error.无法解析类型'someType'"时,如何调试Android数据绑定?无法解析类型'someType'`?

问题描述 投票:0回答:1

不幸的是,我已经经常遇到这个问题了,在我的Android项目中,我使用的是 databinding and click OK.

<layout xmlns:android="http://schemas.android.com/apk/res/android">
  <data>
    <variable name="myClass" type="com.somepackagename.myClass" />
  </data>
</layout>

Make sure that both the variable name and

checkbox are checked. Also make sure to check the

e: error: Cannot resolve type 'myClass'
e: error: cannot generate view binders android.databinding.tool.util.LoggedErrorException:       failure, see logs for details.
Cannot resolve type 'myClass'
    at android.databinding.tool.util.L.printMessage(L.java:134)
    at android.databinding.tool.util.L.e(L.java:107)
    at android.databinding.tool.expr.Expr.getResolvedType(Expr.java:386)
    at android.databinding.tool.expr.ExprModel.lambda$resolveTypes$1(ExprModel.java:618)
 ...

checkbox and enter the following expression:

  • . This way we instruct the debugger to only suspend if the databinding tool prints a log message with an error.
  • Click Done.

At some point during your build, if you have a databinding

, a breakpoint should be reached. In the debugger you should now see the exact error message the logger printed:

Now scroll down the Stacktrace on the left pane of the debug window and click the entry
android data-binding android-databinding
1个回答
1
投票

The final step is easy. Using Android Studio, simply search for this class, for instance using: Edit → Find → Find in Path → "com.somepackagename.myClass". On the right side of the window, select File mask:

You should now see all xml files that caused the issue.Hope this helps someone in the future. Still IMO this is way to complicated. If anyone knows a better way to debug such issues, please let me know :) 基本上,我是按以下方式进行的。

在我的整个项目(相当大)中,我经常使用相同的

  1. 用于许多不同的xml布局。DatabindingDebugging在做了很多重构之后,我现在不能再构建我的项目了,因为出现了以下构建错误。
  2. 虽然错误信息(errorMessage)对我来说很清楚 告诉我是哪个变量名导致了这个问题 不幸的是,它不是很详细,没有告诉我:./gradlew assembleDebug --no-daemon -Dorg.gradle.debug=true -Dkotlin.compiler.execution.strategy="in-process" -Dkotlin.daemon.jvm.options="-agentlib:jdwp=transport=dt_socket\,server=y\,suspend=n\,address=5005"是哪个xml文件导致了这个问题> Starting Daemon哪种类型会导致这个问题
  3. 这使得如果你改变了很多xml布局,就很难找到导致的问题。DatabindingDebugging难道就没有更好的方法来调试这种错误吗?Debug DatabindingDebugging Ctrl + D
  4. Connected to the target VM...不幸的是,我已经经常遇到这个问题了。在我的Android项目中,我使用databinding来绑定类到我的xml布局上,工作正常。基本上我是按以下方式做的: ...
  5. 在花了很多时间之后,我终于找到了导致这个问题的原因,我找到了一种调试这种错误的方法,这种方法总能比较快地找到问题。不过这个设置需要相当多的步骤。+首先,我要感谢这篇优秀文章的作者,他给了我一个很好的想法,让我知道该从哪里开始。1. Java Method Breakpoints
  6. https:/medium.com@dzolnaidebugging-a-databinding-compiler-error-9510f88f4cec。Class pattern: android.databinding.tool.util.L根据上面的文章,下面应该可以快速找到导致错误的方法。Method name: printMessage在Android Studio中添加一个新的配置。编辑→运行配置。给它起一个任意的名字,比如
  7. 并点击确定(即什么都不用改)Enabled在终端窗口中执行。Suspend. 构建过程中应打印 Condition. 即它会等到你调试。kind.name.equals("ERROR")回到Android Studio,在顶部的部分,你的新配置
  8. 应该被选中。点击绿色的调试图标
  9. 或按 ERROR调试窗口现在应该启动,并显示如下内容 Cannot resolve type 'someType'
  10. .与此同时,回到终端窗口,gradle构建应该像往常一样执行。getResolvedType:386, Expr在Android Studio的调试窗口中,手动添加一个新的断点。点击ViewBreakpoints(红色图标,有两个点)。在Breakpoints窗口中,通过点击添加一个新的断点。this.mUserDefinedType = "com.somepackagename.myClass" 左上角的图标,然后选择
  11. 在弹出的对话框中输入以下内容。*.xml
© www.soinside.com 2019 - 2024. All rights reserved.