Android data binding "Missing import expression although it is registered" after upgrade to gradle 5.0

After I upgraded my Android studio and gradle plugin, I ran into similar issue because of the below line. I was using this <import type="java.lang.String" /> in my layout file. Removing this import solved the issue.

Just as in managed code, java.lang.* is imported automatically.


I also face these errors in data binding. I tried with 'android.databinding.enableV2=true', it is not working. After I redo databinding for a layout.xml, I found these solutions. if I'm using 'android.view.View' in layout.xml, I did import View and declare variable like this,

<data>
    <import type="java.util.List" />        
    <import type="android.view.View" />
    <import type="com.example.android.mobilepos.data.pojos.ActionData" />
    <variable
        name="view"
        type="View" />
    <variable  name="actionList"  type="java.util.List&lt;com.example.android.mobilepos.data.pojos.ActionData>" />

And used variable view in like this.

 <EditText
   android:layout_width="wrap_content"
   android:layout_height="wrap_content" 
   android:id="@+id/txt_payment_remark"                           
   android:hint="@string/hint_payment_remark"                            
   android:visibility="@{switch1.checked ? view.VISIBLE : view.GONE}" />
 <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/action_data_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/color_white"
                android:focusable="true"
                android:clickable="true"
                app:actionSource="@{actionList}"
              app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"                    app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
                tools:context=".ui.fragments.NewInvoiceFragment"
                tools:listitem="@layout/fragment_new_invoice">

I also did for Integer.toString() feature like this, but can't import and use Integer in layout.xml. So I shift Integer value to strings.xml with %d label.

 <EditText
     android:id="@+id/txt_qty"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"                        
     android:hint="@string/hint_quantity"
     android:inputType="number"
     android:maxLength="5"
     android:maxLines="1"
     android:singleLine="true"
     android:text="@{@string/shipment_qty(product.qty)}"
     android:textAlignment="center"
     android:textColor="@color/black"
     android:textStyle="bold"                        
     tools:text="1000" />

I hope these will solve your problems.