LoginSignup
1
0

More than 5 years have passed since last update.

RealmObjectのpublicフィールドをデータバインディングで使っていると、androidTestビルドできない

Posted at

ハマった

ここ最近は、Realmもデータバインディングもそこそこよく使われているので、

class Message extends RealmObject {
  @PrimaryKey public long id;
  public String title;
  public String body;
}

みたいなモデルがあって

  <TextView
    id="@+id/message_title"
    text="@{message.title}"

みたいな感じでデータバインディングするケースはよくあると思います。

これに、最近あんまり使われてない気がしてるInstrumented Unit Test(androidTestビルド)が組み合わさると

:app:mergeDebugAndroidTestAssets
:app:transformClassesWithRealmTransformerForDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithRealmTransformerForDebugAndroidTest'.
> javassist.CannotCompileException: [source error] realmGet$title() not found in xx.yy.zz.Message

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2 mins 43.678 secs

みたいなコンパイルエラーになります。

調べてもなぜかそれっぽい情報は出てこない?

https://github.com/realm/realm-java/issues/2936 が全く同じエラーっぽいなー
でも違うな―

よくわからん。

って感じでした。

getter/setterなら大丈夫!

class Message extends RealmObject {
  @PrimaryKey public long id;
  private String title;

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public String body;
}

みたいなモデルにして

  <TextView
    id="@+id/message_title"
    text="@{message.getTitle()}"

ならコンパイル通った。なんで??

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0