简体   繁体   English

在 Android Studio 中,构建 Android Wear 项目,如何在两个模块中包含相同的文件

[英]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.我正在移动设备上成功构建 Android Wear 表盘和连接的应用程序。 The problem is that I have several resource and class files that are referenced in both the mobile and wear modules.问题是我有几个资源和类文件在mobilewear模块中都被引用。 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.我从中构建的骨架应用程序还创建了一个(非构建) DigitalWatch模块,我猜我可以将这些常见文件移到那里,然后从我的 Gradle 构建文件中引用它们。 I've reviewed some of the ideas on Stackoverflow, but the comments suggest they don't work.我已经回顾了 Stackoverflow 上的一些想法,但评论表明它们不起作用。

Here's my project structure.这是我的项目结构。 Common files include res/strings.xml, a utility class, and the google json files.常见文件包括 res/strings.xml、实用程序类和 google json 文件。

项目结构

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我已经成功地将常见的 Java 实用程序类和字符串/可绘制对象移动到一个名为“Common”的单独模块中,并在移动和穿戴 gradle 文件中引用它,如下所示

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.如果将xmlns:app="http://schemas.android.com/apk/res-auto"到布局中的顶部元素,则必须添加导入以在公共模块和资源工作中引用您的 java 类。

The google-services.json I have not been able to move as there is a fixed relative reference to this within the Google libraries. google-services.json我无法移动,因为在 Google 库中有一个固定的相对引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM