It's a starting template that I use for all my Android apps. It is based on the architecture of the Now In Android app by Google. Check out the app from the latest Release.
Warning
Firebase authentication and crashlytics requires Firebase console setup and the google-services.json
file. I have provided a template to ensure a successful build. However, you need to provide your own in order to use all the functionalities.
This template offers Modern Android Development principles and Architecture guidelines. It provides an out-of-the-box template for:
- Connecting to a remote API using Retrofit and OKHttp
- Persistent database solution using Room and Datastore
- Sign In Authentication using Firebase i.e. Google ID and Email
- Bluetooth communication using classic and low-energy (upcoming) protocols
Note
Firebase auth needs setting up first using the SHA fingerprint. Get the SHA fingerprint of the app and add it to firebase console.
It contains easy-to-use Interfaces for common tasks. For example, the following provides utilities for Bluetooth communication:
/**
* BluetoothManager interface provides methods to manage Bluetooth connections.
*/
interface BluetoothManager {
/**
* Attempts to establish a Bluetooth connection with the specified device address.
*
* @param address The address of the Bluetooth device to connect to.
* @return A [Result] indicating the success or failure of the connection attempt.
*/
suspend fun connect(address: String): Result<Unit>
/**
* Returns the state of the connected Bluetooth device.
*
* @return A [StateFlow] emitting the current state of the connected Bluetooth device.
*/
fun getConnectedDeviceState(): StateFlow<BtDevice?>
/**
* Closes the existing Bluetooth connection.
*
* @return A [Result] indicating the success or failure of closing the connection.
*/
suspend fun closeConnection(): Result<Unit>
}
It also contains several utilities and extension functions to make repetitive tasks easier. For example:
/**
* Displays a short toast message.
*
* @param message The message to be displayed in the toast.
*/
fun Context.showToast(message: String) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
/**
* Checks if the app has a given permission.
*
* @param permission The permission to check.
* @return `true` if the permission is granted, `false` otherwise.
*/
fun Context.hasPermission(permission: String): Boolean {
return ContextCompat.checkSelfPermission(this, permission) ==
PackageManager.PERMISSION_GRANTED
}
/**
* Checks if all the given permissions are granted.
*
* @param permissions List of permissions to check.
* @return `true` if all permissions are granted, `false` otherwise.
*/
fun Context.isAllPermissionsGranted(permissions: List<String>): Boolean {
return permissions.all { hasPermission(it) }
}
- Kotlin 2.0
- Jetpack Compose
- Kotlin Coroutines
- Kotlin Flow for Reactive Data
- Retrofit and OkHttp
- Firebase Auth
- Firebase Crashlytics
- Room Database
- Preferences Datastore
- Dependency Injection with Hilt
- Gradle Kotlin DSL
- Gradle Version Catalog
- Convention Plugin
This template follows the official architecture guidance suggested by Google.
This project requires Firebase for analytics. Building the app requires google-services.json
to be present inside the app
dir. This file can be generated from the Firebase Console. After that, run the following from the terminal.
$ ./gradlew assembleDebug
Or, use Build > Rebuild Project
.
Building the release
version requires a Keystore
file in the app
dir. Also, a keystore.properties
file needs to be created in the rootDir
.
storePassword=****
keyPassword=*****
keyAlias=****
storeFile=keystore file name (e.g., key.jks)
After that, run the following from the terminal.
$ ./gradlew assembleRelease