Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - Creating Modules without copying files?

I'm creating projects with dependencies in Android Studio. I know how to link projects by adding modules.

But I realized that 'importing modules' create a copy of the libProject inside the project.

Is there a way to prevent that ? Like an 'external module' ?

Since i'm in charge of both project, I want to be able to push changes to the libProject Repo, without having to copy paste files between folders.

Thanks

like image 904
Philippe David Avatar asked Jul 09 '14 15:07

Philippe David


People also ask

What does make module mean in Android Studio?

Android Studio uses modules to make it easy to add new devices to your project. By following a few simple steps in Android Studio, you can create a module to contain code that's specific to a device type, such as Wear OS or Android TV.

What is AAR file in Android?

AAR files can contain Android resources and a manifest file, which allows you to bundle in shared resources like layouts and drawables in addition to Java classes and methods. AAR files can contain C/C++ libraries for use by the app module's C/C++ code.

Can we import module from source in Android Studio?

Select the source directory of the Module you want to import and click Finish. Open Project Structure Dialog (You can open the PSD by selecting File > Project Structure) and from the left panel click on Dependencies. Select the module from the Module(Middle) section In which you want to add module dependency.

What is multi module project in Android?

A project with multiple Gradle modules is known as a multi-module project. This guide encompasses best practices and recommended patterns for developing multi-module Android apps. Note: This page assumes a basic familiarity with the recommended app architecture.


2 Answers

Yes, you can do it. The module needs to have a Gradle build file set up for it. If it's got that, then in the project you're linking to it, add this to the settings.gradle file at the project root:

include ':libraryName' project(':libraryName').projectDir=new File('/path/to/library') 

where the path you specify in the second line is the path to the directory containing the library's build.gradle file. The path can be relative or absolute.

like image 130
Scott Barta Avatar answered Sep 21 '22 06:09

Scott Barta


The solution:

include ':libraryName' project(':libraryName').projectDir=new File('/path/to/library') 

was not working for me. After couple of wasted hours I figured out the issue. There are two build.gradle files, one for project and one for library name. If the library is in the folder '\MyLib' then there will be a build.gradle in '\MyLib' and another at '\MyLib\app'. You have to point to the '\MyLib\app' and not '\Mylib'.

Hopefully this saves some time for others.

like image 44
cbelwal Avatar answered Sep 21 '22 06:09

cbelwal