Multiple android app projects sharing code in Clean-Architecture - android

I want to create three related android apps (employee, Manager, Secretary) in clean-architecture and also share common classes (utils, Ui & etc.) among all three apps in order to reduce code duplication. Each project has multi-modular clean-architecture design. Would you guide me on how to connect these three projects to the shared classes, please? Is there any sample code for my case?
My project after using clean-architecture book by Alexandru Dumbravan:

I think you might do some separation code between apps. You can merge it in you settings.gradle to merge all apps/libraries in one project.
Here is the example
There is 4 additional code/library in 1 project which is app, xxxapi,xxxauth and xxxcommon.
So you can set your settings.gradle into something like :
include ':app', ':xxxapi', ':xxxauth', ':xxxcommon'
If you already set that code, you can use it in all your code in one project as well.

Related

import and access re-usable static methods (AndroidStudio)

In my former programmer-career I had developed hundreds of small utility functions re-usable in multiple programs .
Now in Android ( strange & new to me ) I would like to do something alike , utilities as playing a sound at certain events , make some standard dialogs etc..
I tried with a new package es.utils with an "add no activity" .
Therein I added a java-class with a private constructor ( so the class cannot be instantiated ) , all the methods in that class declared static.
These methods will be my "functions" ( compare with Javas Math-class ) .
So far so good but how do I call or import these methods in my common-apps & make them visible for AndroidStudio?
Paste and Copy source-code is not a serious option .
All the text-books and tutorials I have consulted remain silent about this theme .
Someone with a practical suggestion ? Thanks in advance!
Eric.S
Today Android Studio uses gradle as the build mechanism.
You can, do some pretty configuring with references as library modules for your own usage.
But if you pretend to make it public you can:
Generate AAR;
Generate JAR if it doesnt contains the resources folders and AndroidManifest
publish as a gradle artefact trough jcenter() and maven() repos [recommended]
I do this by creating an Android library project that contains all of my common reusable code.
I share the project on GitHub then just use Gradle and JitPack to import the library into whatever project I want to use.
Github lets me create version releases so I can safely keep a "point in time" version of my library in case any updates to the library cause changes that could break the projects that use it.

Can I create a project in Android and use it as a base template for future projects

Is it possible to create a project and add libraries such as volley, that will be used in most projects anyway and then copy this project to be used again and again as the base for all future projects?
The only issue I can see there being is with keystores but if I change all of the package names then surely this shouldn't be a problem?
You can create File Templates - explained here.
Short version: Yes. You'll need to create a new Folder iwth your desired template name in
{ANDROID_STUDIO_LOCATION}/plugins/android/lib/templates/other/, create files which contain relevant information, create a folder structure & enter your desired template files.
An example can be found on github.
Yes you can, and that should be a good practice. Android Boostrap doing something similar like it.
You can take a look at base_app_android
Here the excerpt:
Base skeleton structure to start every new project, based on the
design patters suggested by Robert C. Martin (aka Uncle Bob) on his
clean architecture.
base_app_android is the project which we use at Refineria Web to start
any new Android project. It presents a structure of 3 layers, domain,
data and presentation; this approach has been chosen with the purpose
of creating an application that conducts unit testing and also allow
the portability between platforms, mainly iOS.
Yes You can create it as a library and you can use it

Android Studio: multiple apps with library projects in common

I'm migrating from Eclipse to Android Studio, and I've done a bit of reading. I understand the theory of Eclipse workspaces/projects vs AS projects/modules, but I'm having a hard time figuring out how to best reproduce my Eclipse setup, or if it's even what Android Studio wants me to do.
I have two applications. For the sake of illustration, let's call them EmployeeApp and CustomerApp. These are different applications in every sense - different packages, wildly different source, everything; as far as I can see, they are certainly not just product flavours.
However they both use a lot of library modules, and for the most part, they use the same ones. They also live under the same structure in the same repo.
I wrote separate Gradle scripts for both apps before this migration, and that's what I used to import them. In that way, I can import the top level applications, and end up with two projects in two windows, like this:
The trouble with this is that if someone changes a library project, they at the very least need to know whether it's broken the two apps that depend on it, so ideally I want them in the same view.
First question then: now that it's 2016, does Android Studio allow me to do that, and is it regarded as an intended usage?
If so: how do I do it? I've tried importing the missing parts of one into the other using the 'Import Module' feature, but it apparently does very little.
I think I've resolved this myself. Only time will tell if it's actually an appropriate solution in practice or not.
The problem stemmed from the fact that I'd basically created two independent Gradle scripts, i.e:
Android\EmployeeApp\build.gradle
Android\CustomerApp\build.gradle
whereas what made this work was a top-level build as well, i.e.:
Android\build.gradle
Android\EmployeeApp\build.gradle
Android\CustomerApp\build.gradle
This didn't contain much:
dependencies {
project(":EmployeeApp")
project(":CustomerApp")
}
and then build.settings simply included one of these pairs for every project:
include ':Services'
project(':Services').projectDir = new File(settingsDir, './Services')
I then imported that top level build.gradle and almost all was well.
I did have to do a bit more, like move repositories and allProjects to the top level, but this will be specific to whatever you have.

Is it possible to add a externally-maintained project library, without copying?

I'm working with Android Studio 0.5.8.
I have a Working project, and I want to reuse all its contents to make an almost identical app with only another name and different colors.
Basically I want to make a library from the original app and reuse it in various identical apps, but I don't want to copy & paste inside each new app, I want to maintain and develop only one codebase (the project library).
I have read and read, but I can'tt find any real solution.
I tried this in my settings.gradle:
include ':AppCopy1', ':..:LibraryProject'
It works, but I cant use any classes in AppCopy1.
This sounds like a good candidate for Product Flavors. The Gradle build system has support for maintaining a single codebase and building multiple apps from that codebase that only differ by a few files changes. See the configuration examples here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants for details.

Bulk Publishing of Android Apps

We have several apps that will be very similar in layout and code. The only difference is we will be switching out graphical elements, and making changes to a single constants file and strings file. Of course, theres several problems with this -- the first being namespace. Having an app with the same namespace will overwrite any other apps.
What are some suggestions to doing this?
Currently our namesapce is:
com.company.appname
I figured I could do:
com.company.appname.appversion
I've seen post about ant scripts that helps with this, but I'm wondering if theres more fluid solutions now.
I would suggest looking into Android Library Projects to help with this.
I use this approach for a Lite vs. Free edtions of one of my apps. I have a Library project that contains all of the source and most of the resources for the apps and then 2 projects that use the 1st as a library project, one for Lite and one for Full edition.
The two dependent projects each have their own resources and manifest, allowing the namespace to be different and for me to swap in different strings, drawables, etc. depending on the edition.
I tried the Ant approach but it seemed to be much more of a hassle than the Library project approach. Hope that helps.

Categories

Resources