在 Android Studio 中合并模块? [英] Merging modules in Android Studio?

查看:32
本文介绍了在 Android Studio 中合并模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在研究几个模块,我的主要"模块是可编译的,然后是那些我在某些功能和库中乱搞的模块,直到我让该功能以我想要的方式工作而不会破坏我的主要模块.我现在想将我的一个混乱模块的资源和类合并到我的主要"模块中,而不必去各个目录进行复制和粘贴(例如 src 中的子目录),然后系统地遍历所有由于类路径已更改为某某而弹出的错误.

So I've been working in several modules, my 'primary' one that is compilable, and then ones where I mess around with certain features and libraries until I get that feature to work the way I want without breaking my primary module. I now want to merge the resources and classes of one of my mess-around-modules into my 'primary' module without having to go to individual dirs to copy and paste (e.g. subdirs in src), and then systematically go through all of the errors that pop-up because the class path has changed for such and such.

有没有办法合并两个模块而不用做上面的,基本上就是合并build、src、libs?我能找到的最接近的是重构>移动,但仅此而已,离成为可行的解决方案还差得很远.

Is there a way to merge two modules without having to do the above, basically merge build, src, libs? The closest thing I can find is Refactor>Move, but that's it and is nowhere close to being a viable solution.

推荐答案

在构建多模块项目时,如果两个或多个模块定义了同名资源,则会选择优先级较高的模块中的资源.

When building a multi-module project, if two or more modules have defined a resource with same name, the resource from the higher priority module will be selected.

您可以通过打开项目结构(文件 -> 项目结构/Ctrl+Alt+Shift+S)并在依赖项选项卡中单击向上和向下箭头来更改模块的相对优先级.

You can change the relative priority of modules by opening Project Structure (File -> Project Structure / Ctrl+Alt+Shift+S) and clicking on up and down arrow, in Dependencies tab.

如果您要添加对多个库的引用,您可以通过选择一个库并使用向上和向下控件来设置它们的相对优先级(和合并顺序).这些工具从最低优先级(列表底部)到最高(列表顶部)将引用的库与您的应用程序合并.如果多个库定义了相同的资源 ID,工具会从库中选择优先级更高的资源.应用程序本身具有最高优先级,其资源始终优先于库中定义的相同资源 ID.https://developer.android.com/sdk/installing/create-project.html

If you are adding references to multiple libraries, you can set their relative priority (and merge order) by selecting a library and using the Up and Down controls. The tools merge the referenced libraries with your application starting from lowest priority (bottom of the list) to highest (top of the list). If more than one library defines the same resource ID, the tools select the resource from the library with higher priority. The application itself has highest priority and its resources are always used in preference to identical resource IDs defined in libraries. https://developer.android.com/sdk/installing/create-project.html

manifest.xml 文件也将或多或少地直观地合并.不同文件中同一节点的属性相加,除非存在会引发异常的冲突并且您必须解决冲突.每个模块清单的不同节点将被添加到最终清单中.例如,您可以在库模块的 manifest.xml 中定义服务,而无需向主模块清单文件添加任何内容,一切都会好起来的.

Also manifest.xml files will be merge more or less intuitively. Attributes of a same node in different files add up unless there is a conflict which will raise exception and you must resolve the conflict. Different nodes of each module's manifest will be added to the final manifest. For example you can define a service in a library module's manifest.xml without adding anything to the main modules manifest file and everything will be fine.

您可以在此处阅读有关清单合并的更多信息.

这篇关于在 Android Studio 中合并模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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