Skip to main content

Android App

Configure and run the Android App for the first time.

Create signing keys

Open a terminal in the root of the project and run the following commands:

cd androidApp

Replace [DEBUG_PASSWORD] with your desired password. (avoid special characters and passwords shorter than 12 characters)

keytool -genkey -v -keystore debug_keystore.jks -storepass [DEBUG_PASSWORD] -alias androiddebugkey -keypass [DEBUG_PASSWORD] -keyalg RSA -keysize 2048 -validity 10000 -dname "CN=Android Debug,O=Android,C=US"

Replace [RELEASE_PASSWORD] with your desired passwords. (different from the debug password, avoid special characters and passwords shorter than 12 characters)

keytool -genkey -v -keystore release_keystore.jks -storepass [RELEASE_PASSWORD] -alias androidreleasekey -keypass [RELEASE_PASSWORD] -keyalg RSA -keysize 2048 -validity 10000 -dname "CN=Android Release,O=Android,C=US"
tip
  • Can't think of a good password for the keys? Use a password generator. Uncheck the special characters option.
  • If you are having problems with the keytool command, try removing special characters from the password.
  • Save these passwords in a secure place, you will need them later.

Open the project in Android Studio

  1. Open the project in Android Studio by selecting the directory you created while cloning.
  2. Select the project view from the dropdown in the top left corner. android studio file tree project view
  3. Update the rootProject.name property in settings.gradle.kts to match your project name. (will not be the app name)
  4. Sync the project by clicking on the Sync Project with Gradle Files button.

Update local.properties file

Look for the file local.properties in the project root folder and add the following content after the existing content:

DEBUG_PASSWORD=[YOUR_DEBUG_PASSWORD]
RELEASE_PASSWORD=[YOUR_RELEASE_PASSWORD]

replace [YOUR_DEBUG_PASSWORD] and [YOUR_RELEASE_PASSWORD] with the passwords you chose in the Create signing keys section.

Update app name and app id

  1. Replace MobileStack with your app name in androidApp/src/main/res/values/strings.xml. (this will be the app name visibile in the phone)
  2. Replace com.zenithapps.mobilestack.android with your application id in androidApp/src/build.gradle.kts / applicationId. (DO NOT MODIFY THE namespace property)
  3. Sync the project by clicking on the Sync Project with Gradle Files button.
warning

Replace only the applicationId property and NOT namespace otherwise you will have to update the namespaces in all the files.

tip

For applicationId is recommended to use a url that you own, reversed. It will be your unique identifier in the app stores and cannot be changed once your app is published in the stores.

Configure Firebase services

Go to Firebase

  1. Create a new project
  2. Enable Analytics
  3. Use a new Analytics account for this project
  4. Choose the country where your app will be published / will be legally available

Add your Android app

From the overview or project settings / general add an Android app to the project.

  1. Click on the Android Icon under your project name.
  2. Use the same package name as the one you chose in the previous step.
  3. Use your app name as nickname. (No need to add Android as platform will be identified with an icon)
  4. Download the google-services.json file and place it in the androidApp directory.
  5. Skip SHA certificate and adding the SDK.
warning

Make sure you add the google-services.json file to the androidApp directory and not the src directory.

Enable Firebase Auth

  1. From your projects Firebase overview, in the left menu go to Build/Authentication.
  2. Click on Get Started
  3. Go to Sign-in method tab and enable providers Email/Password and Anonymous. Click on Save.

Enable Firebase Firestore

  1. From your projects Firebase overview, in the left menu go to Build/Firestore Database.
  2. Click on Create database
  3. Select a database region where your app will be published / will be legally available.
  4. Select Start in production mode.
  5. Once finished, click on the Rules tab and replace all the rules code with the following:
rules_version = '2';

service cloud.firestore {
match /databases/{database}/documents {

// Match documents in the "users" collection where the document ID matches the user's auth UID
match /users/{userId} {
// Allow read and write access only if the user is authenticated and the userId matches their auth UID
allow read, write: if request.auth != null && request.auth.uid == userId;
}

// Match all other documents
match /{document=**} {
// Deny read and write access to all other documents
allow read, write: if false;
}
}
}
  1. Click on Publish.

Enable Firebase Remote Config

  1. From your projects Firebase overview, in the left menu go to Run/Remote Config.
  2. Click on Create Configuration
  3. Create a test string parameter with the key: TEST and default value: TEST.
  4. Click on Save
  5. Click on Publish changes.

Running the app

In Android Studio:

  1. Create an emulator using the Device Manager or connect your physical device.
  2. Click on the green play button to run the app.
  3. You will see MobileStack running on your device.

Troubleshooting

  • File debug_keystore.jks not found -> Make sure you are in the androidApp directory when running the keytool command.
  • Cause: failed to decrypt safe contents entry: javax.crypto.BadPaddingException -> The password you chose is too short or contains special characters. Alternatively, the password that you have entered in the local.properties file is incorrect.
  • No matching client found for package name -> The package name you chose in the applicationId property is not the same as the one you chose in the Firebase console. Remove the app from the Firebase console and add it again using the correct package name.
  • Deprecated Gradle features: The project is using deprecated Gradle features. Update the Gradle wrapper to the latest version. -> Update the Gradle wrapper to the latest version.

If you are having any other issues, please contact us at support@zenithapps.com and we will be happy to help you.