loloof64
loloof64

Reputation: 5392

Sharing a library or reusing it in another project

Using android studio 1.0 for my project, I plan to code a library module inside it. But I am wondering whether sharing only the library module (for example in its own github repository) is easy : I mean, someone fetching this repository, can integrate it as a library module in its own project easily. Also, does the library module has to define at least an activity, or can it just contain independents classes and resources ?

Of course, I also plan to share the global project on a github repository.

So what is the "safest" and easier way to proceed ?

Apologizing if the question may seem too obvious or bad explained.

Upvotes: 0

Views: 95

Answers (2)

hidro
hidro

Reputation: 12541

Since you are using Android Studio, I assume you use Gradle as the build system. With that assumption, below are my answers:

  1. Your library project needs not have Activity, but will need AndroidManifest.xml and a Gradle project layout (src, res folder etc).
  2. If your library project is hosted on Github (or locally outside the root folder of the main project you plan to use it), then you can use Git submodule like lassombra suggested to bring it under root folder of main project.
  3. Once you have the library under the root folder of your main project, you can use Gradle multi-project setup to link them.

Upvotes: 1

lassombra
lassombra

Reputation: 427

The only real way to separate a project into multiple git repositories is through submodules. It's not a bad concept, but what it effectively means is that you have a git repository inside another. One the remote side, they are separate repositories with one being included via submodule.

More information, and the command line tools you'll need to get started can be found at: http://git-scm.com/book/en/v2/Git-Tools-Submodules

Note, there is a lot of hate for submodules, and some of it is earned. It's not intuitive and is often considered an expert Git feature. For that reason, I recommend you read it thoroughly and make sure you understand. Perhaps even throw together a couple of unrelated repositories to play with. BTW, you can have a git repository on your computer anywhere (git init --bare to create it). Then you can clone it anywhere else with git clone file:///<your-path-here> Thus your local and remote are on one computer so you can play/learn without having to create more repositories on git hub or some such.

Upvotes: 1

Related Questions