How to use android databinding within a library

无人久伴 提交于 2020-05-13 06:08:27

问题


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)

回答1:


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

dataBinding {
    enabled = true
}



回答2:


Just update the gradle file of your app

dataBinding {
 enabled=true
 }


来源:https://stackoverflow.com/questions/38442332/how-to-use-android-databinding-within-a-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!