Gong is Xmartlabs' official Android template project, written in Kotlin, and focused on providing a solid app architecture. One of the main objectives of this project is to supply a good starting point for all new android apps, which lets you move forward fast using the latest Android Components and libraries. We're using "clean architecture" to structure, decouple, expand, and maintain the code.
The architecture is based on the Model-View-ViewModel (MVVM) Pattern where there are 4 layers within the application:
- Domain layer - contains high-level abstraction of the application domain (like repositories, data access) and the use cases, which contain all of the application's business logic & domain rules.
- Data layer - implements domain layer abstractions, the
DataSources
, related to data persistence, REST calls, etc. - Device layer - implements domain layer abstractions that are not related to data persistence or user interface but are specific to the android platform: android services, cloud messaging, and many others.
- Presentation (UI) layer - all the functionality related to the Android user interface: activities, fragments, views
The core libraries for the communication between layer components are: LiveData, used to notify the UI changes and Coroutines, used to perform all background tasks.
The main libraries that we are using are:
- Android Architecture Components - Jetpack:
- LiveData which provides data objects that notify views when the underlying database changes.
- ViewModel which stores UI-related data that isn't destroyed upon app rotation.
- Android Navigation Component used to navigate across different pieces of content within your app.
- Room, a SQLite object mapping library.
- Coroutines for asynchronous programming
- Coil, an image loading library for Android backed by Kotlin Coroutines.
- Koin, a lightweight dependency injection framework for Kotlin.
- OkHttp and Retrofit for network communication.
- AndroidSwissKnife a set of extensions, helpers, and useful classes.
- Timber one of the most popular loggers on Android.
- Stetho, a sophisticated debug bridge for Android applications.
- LeakCanary, a memory leak detection library for Android.
- AndroidSnapshotPublisher, one of the most important tools used in the QA process, it's a Gradle plugin that prepares and distributes deliverable versions easily when they are ready to test.
To use this template, you can use the gong_setup.sh script that automatizes the setup process. You can run it remotely executing the following command:
bash <(curl -s https://raw.githubusercontent.com/xmartlabs/gong/master/gong_setup.sh)
It will clone and setup all variables that you need. If you prefer to do it manually, you have to follow these steps:
- Clone the project
- Update the
applicationId
in the app's build gradle file. - Change the package structure based on your application id.
The app's version name is defined in the project's Gradle file. The app's version code is autogenerated based on the app's version name.
You have two files to define your constants:
config.properties
which stores all of the app's configuration, like the backend's base URL, for example.
secrets/keys.properties
which contains all of the secrets in your app, like a given API key for a third party service.
That environment's variables are injected in the app's build.gradle, and they are accessible via the BuildConfig
generated file.
The app access to that variables using the Config file.
The keystores are stored in the secrets
folder, which is not tracked in git.
The library versions are managed in a versions Gradle file
The app uses two flavors, one for production (prod
) and another for development (dev
) build.
Each flavor defines and application class (App.kt), that is used to define custom configurations in each one. For example, the navigation logger listener is defined only for development builds.
For an answer to this question you can check the current project status and if you happen to come up with a new idea you can always open a new issue!
Made with ❤️ by XMARTLABS