Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use android databinding within a library

Is it possible to use Android DataBinding within a library project? I did create a library to be used for other people. Within this library I did use Android DataBinding. It did work on the same Android Studio project as a module, but when i install it to my local maven repo it wouldn't compile because of the generated files couldn't be found. As I checked the aar file, i couldn't find the generated databinding folder as well.

The following error will be produced:

error: cannot access HeaderToolBarBinding
class file for com.test.library.shared.databinding.HeaderToolBarBinding not found
 Consult the following stack trace for details.
 com.sun.tools.javac.code.Symbol$CompletionFailure: class file for    
 com.test.library.shared.databinding.HeaderToolBarBinding not found
 1 error

Does anyone how we could solve this?

So,

 - Shared project
 ---> App (include library by compile project(":shared")
 ---> Shared library (with DataBinding enabled)

 - Project other people
 ---> App (include library by Gradle dependecies)
like image 692
user447811 Avatar asked Jul 18 '16 17:07

user447811


People also ask

Can we use DataBinding and ViewBinding together?

Yep, we don't use <layout> ViewBinding, because on DataBinding we must add that layout tag to generate Binding class and it's different with ViewBinding which automatically generates all layout to Binding class.

Is DataBinding good Android?

Using data binding can lead to faster development times, faster execution times and more readable and maintained code. Android data binding generates binding classes at compile time for layouts.


2 Answers

For DataBinding to work in an application using your library, both need to enable DataBinding in their build.gradle file:

dataBinding {
    enabled = true
}
like image 107
qinmiao Avatar answered Sep 22 '22 19:09

qinmiao


Just update the gradle file of your app

dataBinding {
 enabled=true
 }
like image 20
S.D Avatar answered Sep 24 '22 19:09

S.D