In Android Studio, building an Android Wear project, how can I include the same file in both modules

元气小坏坏 提交于 2019-12-21 05:41:34

问题


I am successfully building an Android Wear watch face and connected app on the mobile device. The problem is that I have several resource and class files that are referenced in both the mobile and wear modules. The skeleton app I built this from also created a (non-building) DigitalWatch module and I'm guessing I could move these common files in there and then reference them from my Gradle build files. I've reviewed some of the ideas on Stackoverflow, but the comments suggest they don't work.

Here's my project structure. Common files include res/strings.xml, a utility class, and the google json files.


回答1:


I've successfully moved both common java utility classes and strings/drawables into a seperate module called "Common" and reference it in both the mobile and wear gradle files as follows

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':common')
    ...
}

You will have to add imports to reference your java classes in the common module and resources work if you add xmlns:app="http://schemas.android.com/apk/res-auto" to the top element in your layouts.

The google-services.json I have not been able to move as there is a fixed relative reference to this within the Google libraries.



来源:https://stackoverflow.com/questions/35444035/in-android-studio-building-an-android-wear-project-how-can-i-include-the-same

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