Skip to content
Pablo edited this page Apr 27, 2021 · 8 revisions

Change the App logo

For changing the training logo go to the path project/app/src/debug/res/mipmap-X/ic_launcher and copy/paste your own ic_launcher.png in all mipmap-X directories.

mipmap-X, where is X, is a specific screen density.

For the production logo, the process is the same but instead, you will find the logos in the path project/app/src/main/res/mipmap-X/ic_launcher copy/paste your own ic_launcher.png in all mipmap-X directories

You should be able to visualize your icons in Android Studio here too.

Change package name

Applications are identified in the app stores by their _applicationId _string which must be unique per store. The official string is com.dhis2. If you try to upload the application to the Google Play store you will get an error message about that. This can also happen in case you are using Mobile Device Management tools that allow you to upload your specific applications. If these applications are going to be stored in the Google Play store as most of them do, you will need to change the applicationId. If you would like to change the applicationId go to the file build.gradle (Module:app) and scroll down until you see defaultConfig

Change “com.dhis2” to the new ID that you want.

You can read more about the applicationId in the official Android page

How to generate a Keystore and sign the APK

By default, the Android system requires that all installed applications be digitally signed by a certificate whose private is held by the application developer. Android uses the certificate as a means of identifying the author of an application and establishing trust relationships between applications. If you try to install an APK without being signed Android will prompt an alert dialog telling you that the APK is not secure, if you proceed and click “Accept” the apk will be installed.

Be aware that If you want to upload the APK to the Google Play Store or some other stores you will be forced to sign the APK, for Github you do not need to sign the APK. In any case, we do recommend you sign your APK for security reasons.

For signing the APK you first need a keystore that can be easily generated with Android Studio. Go to top menu “Build” > “Generated Signed Bundle / APK”

Click on “APK” and ”Next”. Then click on “Create new …”

After you click on “create new…” you will be asked to fill the following form. Key store path: Choose a path where you want the Keystore to be generated. Password and Alias Password: Choose two secure passwords (they do not need to be the same). The remaining fields are direct.

Now clicks “OK” and then you will have to choose a build variant, “release” is fine, after some time the APKs should be generated and you can find them signed in the path project/app/build/outputs/apk.

Important: Once you have generated your Keystore please do not upload it to any public website, also you will need to sign always with this Keystore for future updates.

You can read more about the signing process in the official Android documentation page

Version name, code and chaning library versions

Everytime you want to create a new apk updated you will need to increase the version code, for doing so go to the directory /project/buildsystem/dependencies.gradle

Then you should increase vCode and change vName to the one you want.

Configure OpenID / OAuth

Since version 2.4. The DHIS2 android app supports login with an OpenID or OAuth provider. This feature is not available by default, you need to add the configuration provided below and distribute your own apk. OpenID has to be enabled in the web as well and the user OpenID parameter must be configured.

Under the app/src/main/res/raw you will find the openid_config file.

{
    "serverUrl": "<your server url>",
    "loginLabel": "<text to display in the open id login button>",
    "clientId": "<client id from the auth provider>",
    "redirectUri": "<redirect uri from the auth provider>",
    "discoveryUri": "<openid discovery url from the auth provider",
    "authorizationUrl": "<authorization url from the auth provider>",
    "tokenUrl": "<toker url from the auth provider>"  
}

How you should fill this file depends on the provider you are using. The following example shows how the file would look like using Google as the provider:

{
    "serverUrl": "https://play.dhis2.org/android-current",
    "loginLabel": "Login with google",
    "clientId": "CLIEND_ID_PREFIX.apps.googleusercontent.com",
    "redirectUri": "com.googleusercontent.apps.CLIEND_ID_PREFIX:/oauth2",
    "discoveryUri": "https://accounts.google.com/.well-known/openid-configuration",
    "authorizationUrl": null,
    "tokenUrl": null
}

For OpenID providers it is recommended to use the discoveryUri parameter if possible instead of the authorizationUrl and tokenUrl.

The next step is to modify the AndroidManifest.xml file. In this file you will find the following code and will need to replace the scheme so that the android app can be relaunched after a successful login.

<activity   android:name="net.openid.appauth.RedirectUriReceiverActivity"
            android:exported="true"
            tools:node="replace">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="<your redirect url scheme>" />
            </intent-filter>
        </activity>

Following our example, the Google scheme would be: com.googleusercontent.apps.CLIEND_ID_PREFIX

When launching the app, a new button will be displayed in the login screen.

OpenID providers and configuration guidelines

Here you will find a list of available providers and how to get any info needed to set the openid_config file.

Clone this wiki locally