如何在库中使用android数据绑定 [英] How to use android databinding within a library

查看:56
本文介绍了如何在库中使用android数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在库项目中使用Android DataBinding?我确实创建了一个供其他人使用的库.在该库中,我确实使用了Android DataBinding.它确实可以在与模块相同的Android Studio项目上工作,但是当我将其安装到本地Maven存储库时,由于找不到生成的文件,它将无法编译. 当我检查aar文件时,我也找不到生成的数据绑定文件夹.

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.

将产生以下错误:

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?

所以

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

 - Project other people
 ---> App (include library by Gradle dependecies)

推荐答案

要使DataBinding在使用您的库的应用程序中工作,两者都需要在其build.gradle文件中启用DataBinding:

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

dataBinding {
    enabled = true
}

这篇关于如何在库中使用android数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆