I have to create 5 Android Application with some common modules. As I have think, I have to create one project with all the optimization and then copy paste for other projects but in that scenario we have to change all the resources. All the other things will be same.
As Android Studio is best IDE, Is it providers any functionality to make that type of functionality with easiest way. Something like Common Modules or Libraries.
Any Help, It would be appreciated. Thanks.
create repository in maven central and add your library there,then you can add your library by gradle
here is link for publishing your library to repository
Related
I have an Android project in which I have added Android library as a module and use it within the project. Android library module is part of the project.
what I want to do is, remove the Android library from the project and host it in Github and use the Android library as a dependency in Android project.
Is that possible, if so how can I achieve that please.
If you think I should not be creating a Android library within the Android project I want to use it in, and create Android library as a separate project do let me know as well. (But this was it is a bit hard to debug I think)
Your suggestion and advice will be very helpful
Thanks
R
You need to publish your Library to Github Packages in order to use it as a dependency.
Follow this tutorial to do it.
Update 1
Another way to do that is by using JitPack. You just need to publish your library into Github repository and then you create a dependency using JitPack from that repo.
I have read some sample codes, I find that many project use library module structure, you can see Image A.
Could you tell me the benefit to use library module in Android Studio ?
What code do I need to place it in library ?
And More, both app and lib module use the same namesapce in the sample code, I don't know if it's suitable, could you tell me ?
Image A
Library module gives you two options to create library Android and Java.
Android library module-> Android library compiles into an Android Archive (AAR) file that you can use as a dependency for an Android app module . It allows you to add android specific components like resources and manifest file, which allows you to bundle in shared resources like layouts and drawables in addition to Java classes and methods.
Java Library -> It builds a JAR file. JAR file is useful for many projects especially when you want to share code with other platforms. But it does not allow you to include Android resources or manifest files, which is very useful for code reuse in Android projects. So when you do not need any android specific resources in library you should create a java library.
Library modules are beneficial for projects :-
When you're building multiple apps that use some of the same components, such as activities, services, or UI layouts.
When you're building an app that exists in multiple APK variations, such as a free and paid version and you need the same core components in both.
Quoted from developer.android.com
Other than that same namespace is not problematic unless you have same package name inside App and libraries . You should use a different namespace for libraries.
PS-> If you are familiar with Clean Architecture, The idea behind most of the software design pattern is Separation of concern . In Clean architecture a project is divided into multiple modules. When you implement clean architecture in android you'll see that some of the module you can create as Java library like domain module. Creating module is really useful to follow re-usability and SOLID principles and Inversion of control.
Firstly, don't look into the package name declared in the java directory. Look into the manifest file. You can see that these modules have different package name. It means that all modules in a project must have different package name.
Regarding to your question, what are the benefit of naming library module as lib?
There's no benefit at all. Some people are comfort with lib name, so they can differentiate the demo and library module easily. However, using lib as library's module name requires you to add additional configuration in the lib/build.gradle, i.e. archiveBaseName. This Gradle attribute will rename the JAR/AAR from lib.aar to work-runtime.aar, so people can use it like this:
implementation "androidx.work:work-runtime:$work_version"
If archiveBaseName is not set, people will use it like this:
implementation "androidx.work:lib:$work_version"
In real case, let's take my open source library as the example, MaterialPreference. I used to use lib name on this project, but now I think lib is not a good module name. Using materialpreference as module name will remove additional configuration archiveBaseName. So I feel it is more simple.
So I was going through clean architecture in android, really liked it how people even create separate projects for domain, data and presentation layer. I tried to create my own project for clean architecture but couldn't set up different projects for domain, data and presentation layers.
How can I accomplish this kind of project architecture?
https://github.com/android10/Android-CleanArchitecture
Create one project as your main project of type Android Application Project. The separate layers can be added as library modules to your main project.
Then you just need to add these library modules to your gradle file as dependencies. Android studio will usually take care of that. But just in case you needed to change the order of dependencies, you can do that in the gradle files of each module.
What is the best way to create an Android project and duplicate it?
I would like to have projects that inherit a class that is responsible for the configurations and the base project to bug fixes and improvements.
Another problem that comes to mind is the design that some projects may change, for that matter should be able to add in my project resource folder that inherits the resources to change.
Thank you very much!
As for the duplication of project: you can easily copy-paste the whole project's structure and then from Eclipse you can do New Project -> Android Project -> create project from existing source.
What you are actually asking about, if I am not wrong, is Android Library project. This is a project that you can use to add on the source of other projects. You can read about android library projects here and in the linked page here.
I would use github fork system for inheriting projects and files. Take a look at github, create an account. Moreover, there is google code and tortoise svn alternative.
I want to build a java library with some useful things I done to Android. Just like my other project: https://github.com/MarkyVasconcelos/Towel
My question is, what is the best way to share a library on Android?
Source codes from a entirely Android project(res, src, Manifest, etc..)?
Only source codes(.java)?
A generated jar with the 'src' folder?
Thanks.
I'd distribute an Android library project. I have several such projects in my various GitHub repositories -- those links are just three of 'em.
Although never done myself I think you have to provide an Android Library Project if your library contains android specific content.