Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

Project structure

like image 567
Opus1217 Avatar asked Feb 16 '16 22:02

Opus1217


1 Answers

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.

like image 113
CodeChimp Avatar answered Jun 01 '23 07:06

CodeChimp