Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging modules in Android Studio?

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.

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.

like image 428
Kurt Wagner Avatar asked Jul 15 '14 21:07

Kurt Wagner


People also ask

Can we merge 2 projects in Android Studio?

From Project view, click right click your project root and follow New/Module. 1. b. And then, choose "Import Gradle Project".

What is merged manifest in Android Studio?

The manifest merger tool combines all XML elements from each file by following some merge heuristics and by obeying merge preferences that you have defined with special XML attributes. This page describes how manifest merging works and how you can apply merge preferences to resolve merge conflicts.

What is multi module in Android?

A project with multiple Gradle modules is known as a multi-module project.

What are modules Android studio?

Modules. A module is a collection of source files and build settings that allow you to divide your project into discrete units of functionality. Your project can have one or many modules, and one module may use another module as a dependency. You can independently build, test, and debug each module.


1 Answers

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.

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.

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

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.

You can read more about manifest merging here.

like image 110
Ashkan Sarlak Avatar answered Nov 15 '22 00:11

Ashkan Sarlak