Giter VIP home page Giter VIP logo

reproduce-databinding-dfm-issue's Introduction

The Issue

The issue is when we have a project that enables databinding and dynamic feature. More specifically when we have a logic in our dfm layout that accesses some resources from application or library module.
See this activity_dynamic.xml example:

<TextView
   android:id="@+id/text_view_greeting"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textSize="16sp"
   android:text="@{viewModel.login ? @string/text_login : @string/text_logout}"/>

@string/text_login and @string/text_logout are from app module. So when we build the app, databinding will create a generated file called ActivityDynamicBindingImpl, and this file will contain some logic like this:

// read viewModel.login ? @android:string/text_login : @android:string/text_logout
viewModel... = ((viewModelLogin) ? (textViewGreeting.getResources().getString(R.string.text_login)) : (textViewGreeting.getResources().getString(R.string.text_logout)));

It will make compilation error because dynamic module doesn't know R.string.text_login and R.string.text_logout.
So, we need to change them to full name com.yeuristic.reproducedatabindingdfm.R.string.text_login and com.yeuristic.reproducedatabindingdfm.R.string.text_logout.
But we can't do that since it is generated file.

How to reproduce

Run the project and these errors will show up:

error: cannot find symbol viewModelLoginTextViewGreetingAndroidStringTextLoginTextViewGreetingAndroidStringTextLogout = ((viewModelLogin) ? (textViewGreeting.getResources().getString(R.string.text_login)) : (textViewGreeting.getResources().getString(R.string.text_logout)));
symbol:   variable text_login
location: class string
error: cannot find symbol viewModelLoginTextViewGreetingAndroidStringTextLoginTextViewGreetingAndroidStringTextLogout = ((viewModelLogin) ? (textViewGreeting.getResources().getString(R.string.text_login)) : (textViewGreeting.getResources().getString(R.string.text_logout)));
symbol:   variable text_logout
location: class string

Workaround

Change your databinding logic to this

<TextView
    android:id="@+id/text_view_greeting"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:text="@{viewModel.login ? textViewGreeting.getResources().getString(com.yeuristic.reproducedatabindingdfm.R.string.text_login) : textViewGreeting.getResources().getString(com.yeuristic.reproducedatabindingdfm.R.string.text_logout)}"/>

Or you can uncomment it from activity_dynamic.xml that I've provided.

reproduce-databinding-dfm-issue's People

Contributors

yeuristic avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.