question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android build error when using data binding with realm object

See original GitHub issue

Hi, i have this problem.

If i have a class that inherits RealmObject

import io.realm.kotlin.types.RealmObject

class User: RealmObject {
    var name: String = ""

And i try to make it as live data

class LoginViewModel : ViewModel() {

    val user = MutableLiveData<User>()

And i use data binding to display its value somewhere in my layout

            <androidx.appcompat.widget.AppCompatTextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@{viewModel.user.name}"
                tools:text="hi User"/>

I will get this error when i try to build the app

/path/to/my/android_app/app/build/generated/source/kapt/debug/com/my_app/android/databinding/FragmentLoginBindingImpl.java:215: error: cannot access User
    private boolean onChangeViewModelUser(androidx.lifecycle.MutableLiveData<com.my_app.android.database.models.User> ViewModelUser, int fieldId) {
                                                                                                              ^
  bad class file: /path/to/my/android_app/app/build/tmp/kotlin-classes/debug/com/my_app/android/database/models/User.class
    undeclared type variable: T
    Please remove or make sure it appears in the correct subdirectory of the classpath.

Any insight on this would be appreciated, Thanks!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
robbieadicommented, Jul 14, 2022

@robbieadi I created a sample based on the official KotlinCoroutineswithArchitectureComponentsLiveDataViewModelLifecycle with Realm, it works as expected. Could you please have a look and see if this matches your use case, or find a way to make it crash so we can have a repro to investigate

Cheers KotlinCoroutineswithArchitectureComponentsLiveDataViewModelLifecycle.zip

Ah, I see. I was using version 1.0.0, but once I updated it to 1.0.1 I can now build the app successfully. As for reproducing the error you can easily reproduce it by downgrading the realm to version 1.0.0 in your KotlinCoroutineswithArchitectureComponentsLiveDataViewModelLifecycle app.

Thanks for your help @nhachicha!

0reactions
rorbechcommented, Jul 21, 2022

Duplicate of #901

Read more comments on GitHub >

github_iconTop Results From Across the Web

Realm and Android DataBinding - Stack Overflow
The problem seems to be the fact that i use databinding and Realm in the same application. realm. commitTransaction(); I don't understant what ......
Read more >
Confusing/missing error messages using Realm and data ...
Try to build and observe that you only get errors that data bindings were not generated (e.g. Error:(3, 38) error: package com.example.android.databinding ......
Read more >
Applying Data Binding for Views | CodePath Android Cliffnotes
If you see an error message such as cannot resolve symbol 'ActivityMainBinding' then this means that the data binding auto-generated class has not...
Read more >
3 Methods for Solving Android Data Binding Errors - Atomic Spin
1. View All of the Build Output · 2. Fall Back to the Old Data Binding Compiler Temporarily · 3. Invalidate Caches.
Read more >
Realm: Create reactive mobile apps in a fraction of the time
(Android's UI thread is a Looper.) This means the Realm instance will be periodically updated to the latest version. This lets you keep...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found