I'm really new with android developing. But I know how to upload a library to GitHub and include it in an android project. Recently, I'm working on some android apps, and I realized that I need to use some layouts and classes for all the apps. So, I created an android library and kept that inside all the project files. Then I came to know that I can simply upload that library to GitHub and use it for all the projects. But I'm not sure if it's a good idea. Is there any advantage if I upload it to GitHub?
1 Answers
In general, using a source control (git or other ones) is always a good idea given that your local filesystem can crash or you may want to revisit certain revisions you made to your project. Github is very popular and hosts several highly used projects, so it is no doubt a good place to upload. However, you must know that if you don't have their paid account, the project will be public (at this time, free accounts don't have a way to create private projects). Are you developing as hobby and do you mind if others see / take the code and reuse (hopefully under the licensing terms you specify)? Or is that something you're doing for an employer? In that case you should consult with the employer if this is OK.
Now as for sharing this module across projects, I don't think github has a secret sauce here. You could always build your library once and drop it in as dependency into all your apps, without having to copy its source code into each project. You may also want to look into integration with maven / gradle build systems, which Android Studio uses. For example, third party libraries often are available as downloadable libraries from maven central, and you can add a couple of lines to your build.gradle to go fetch a specific version of your library from maven central, rather than manually adding that library jar to the project that is using it. If your library code is on github, there are ways to publish to maven central from github ( http://datumedge.blogspot.com/2012/05/publishing-from-github-to-maven-central.html ) but I don't have experience with that step.

- 51
- 2
-
Thank you so much. That helped a lot. I created my library using New Module option. So, I'm not using any .jar file. And actually, in my projects, I'm using some third-party libraries by including them in dependencies inside build.gradle. That's how I came to know how I can upload my own library to GitHub. But I was not sure if that will make a big difference. Will it somehow decrease the space taken by my app? Logically it shouldn't. But I don't know how exactly it works. And I'm fine with uploading it publicly. Because I'm gonna kind of donate these apps to my university sports societies. – Debjit Mandal Sep 25 '17 at 00:11
-
@DebjitMandal I don't think there would be a difference in the binary size whether you download before compile, or add it manually. But the gradle download option appears cleaner to me since upgrading your dependent library to a new version is somewhat easier. Say you push a new revision of your library to maven central, you would just need to change the version number in build.gradle and it'll be handled for you, rather than replacing the jar manually in each project. By the way if my earlier answer answered your question please mark it as answer. – Karthik V Sep 25 '17 at 00:17
-
Oh! Now I see it. So, it will be useful for version control. Thanks again. And yeah, now I marked it as an answer. Actually, this is the first time I'm using StackOverflow to ask a question, so I forgot about the green tick. – Debjit Mandal Sep 25 '17 at 01:01