I mostly being stuck with android data binding BR issue. There is single activity.xml always but generated binding class showing error. Please let me know how to resolve this issue.
Custom binding class name resolved my problem
<data class="ContactItem">
…
</data>
Answer:
If you are using the Room ORM
Check your DAO clazz
Example:
@Update
String update(Call call);//fail
@Update
long update(Call call);//fail
@Update
int update(Call call);//success databinding build
@Update
void update(Call call);//success databinding build
Answer:
I’d it by adding android.databinding.enableV2=true in Gradle properties. It was working fine.
Answer:
I had the same problem, and it was because I had a reference to a variable of an unknown class
<variable name="handler" type="com.example.org.UnknownClass" />
I just had to correct this mistake.
Answer:
If you are using the Room ORM, review them if you’ve recently had some changed. Any problem in parsing SQL
queries and also return type of your method that should fully match with the query result can affect on data binding and show unnormal errors.
I had a similar problem:
@Query("SELECT * from NotSellingReason where NotSellReasonId > 0")
List<ReasonModel> getUnvisitingReasons();
I had a wrong generic type here. I must used ReasonEntity
instead of ReasonModel
and it takes a long time to get it!
Another problem which can fail the data binding is about Dagger
DI. If you are using DI in your project be sure that all injected
classes, … are provided or bound by the dagger.
Answer:
In my case, it was the problem with Dagger 2 version. 2.17 and above (The latest version as of today is 2.20) didn’t work. Changing back to 2.16 solved the problem for me.
See more discussion about this here
Answer:
You can get this error when you include a layout in xml.
<include layout="@layout/any_layout" />
to include another layout in your xml, follow this
https://stackoverflow.com/a/38681418/1893503
Answer:
I was getting 37 of this duplicate errors, and it was all due to a wrong import in 1 layout file
<import type="android.view.View"/>
<variable
name="viewModel"
type="wrong.package.name.SViewModel"/>
I found it by opening all my layout xml files and checking it manual. The error itself was totally unrelated though, as it is still there if I manually go to /build/generated/data_binding…, but build doesn’t fail anymore and no reports no errors or warnings.
Answer:
In my case this problem was caused by the fact that in Entity class of Room ORM names of setter and getter of private field did not match with java bean naming convention.
Answer:
In my case it was happening because i changed List
to ArrayList
;
Issue resolved when changed back to List
;
@Query("SELECT * FROM " + PurchaseConstants.TABLE_NAME + " ORDER BY purchaseTime DESC")
List<Purchase> getAllPurchases();
Answer:
I had the same problem. In my case I was using Room and I did not write setter method in Entity
class. So you also check in your case.
Answer:
in my case the problem was because of private modifier for onclick method assigned with butterknife ,make sure all fields and methods assigned with butterknife are public
Answer:
In my case the problem was because the ARouter not support kotlin very well。when I use @Autowired annotation ,build failed and tips dataBinding not found ,duplicate class found in
the file ActivityLoginBinding。Then add @JvmField before @Autowired,It works and build success。
so,when you use AndroidStuido conver Java to Kotlin,Be careful,Kotin files generated in this way may have syntax errors。It could be some Java static function, the annotation of the @bindingadapter in databinding, converted to kotlin, and you get an error.Solve this, and you’re done
for example in Java
@BindingConversion
public static String converStr(CommonUser user) {
return user.getAge() + user.getName() + user.isSingle();
}
//同上,不需要显示因如何调用,在xml中即可使得textview有一个 bg 的属性,app命名空间的,
@BindingAdapter({"bg"})
public static void randomName(TextView tv, String color) {
tv.setTextColor(Color.parseColor(color));
}
when use this in kotlin,like this:
//this is root node in the kotlin file ,no {}
@BindingAdapter("srlEnableRefresh")
fun randomName( tv:TextView, color:String) {
tv.setTextColor(Color.parseColor(color))
}
or
object Tools{
@JvmStatic
@BindingAdapter("srlEnableRefresh")
fun randomName( tv:TextView, color:String) {
tv.setTextColor(Color.parseColor(color))
}
}
I hope this answer answers your question.My English is Very Poor ! ^ ^
Answer:
I’m using Kotlin + dagger + data binding in my project. This approach should work irrespective of dagger2 version.
Things I did to fix my issue:
-
made
android.databinding.enableV2=false
in gradle.properties file and clean & rebuild -
was able to see the actual error related to dagger2 incorrect scope
-
Fixed my dagger graph and other import statements
-
set back to
android.databinding.enableV2=true
Answer:
if you are using room persistence library ,check again about it code. İ was get same issue and after looking my code and i saw. This issue about room persistence..
Finally ..
İ am using Room Persistence library ,i am check my all code and i found. Check your room model class.
Answer:
for me replace kapt to annotationProcessor worked
annotationProcessor "com.android.databinding:compiler:3.1.3"
Answer:
There are many reasons for this problem. You can try this command. worked:)
gradlew build
Answer:
Also stumbled on this and damn, it sucks when it happens. Fair way, i’d go these two ways:
-
because the binding is not fully generated, you might not get to the interesting build errors (like room trying to generate you it’s boilerplate), therefore you should increase -Xmaxerrs flag for maximum number of shown errors
-
in my case, the inspiration came to switch to another Android Studio and Gradle plugin version (in AS 3.4, beta channel, i got the actual build errors)
Tags: androidandroid, class, file, login, xml