Skip to content

Local Deployment for Testing

Marcos Campos edited this page Jul 4, 2024 · 6 revisions

The DHIS2 Android SDK is typically utilized by publishing it to Maven. Detailed instructions for this can be found on the release process page. However, during development, you may want to test the SDK directly within an application without going through the full Maven publication process. This guide explains how to simplify this process by publishing the SDK to your local Maven repository and consuming it from there.

Deploying to Maven Local

Step 1: Modify SDK Version Name

Before publishing to your local Maven repository, it is recommended (though not mandatory) to change the version name of the SDK to something distinctive. This helps in easily identifying your custom build, especially when searching across Maven Central, Maven Snapshots, and Maven Local.

For instance, if you're implementing a fix for event download, you might set the version in the gradle/libs.versions.toml file as follows:

[versions]
dhis2AndroidSdkVersion = "1.10.1-EVENTDOWNLOAD"

Step 2: Publish to Maven Local

Execute the following Gradle command to publish the SDK to your local Maven repository:

./gradlew publishToMavenLocal

Step 3: Verify Local Maven Repository

You can check your local Maven repository to ensure that the new version has been published. On Linux systems, the local repository is typically located at ~/.m2/repository/. For the DHIS2 Android SDK, the path would be:

~/.m2/repository/org/hisp/dhis/android-core

On Windows systems, the local repository is typically at C:\Users\<yourUser>\.m2\repository\.

C:\Users\<yourUser>\.m2\repository\org\hisp\dhis\android-core\

Consuming a Local Library

Step 1: Add mavenLocal() to Repositories

To consume the locally published library, declare the mavenLocal() repository in your application's build.gradle file. If your application is modular, ensure that each module consuming the library includes this declaration.

In the repositories section of your build.gradle file, add:

repositories {
    ...
    mavenLocal()
    ...
}

Step 2: Update the SDK Version

Next, update the SDK version in your application's dependencies section or version catalog to match the custom version you published. For example, if you're using the Gradle version catalog, it will look like this:

[versions]
...
dhis2sdk = "1.10.1-EVENTDOWNLOAD"

Ensure that this version matches the one you specified in the gradle/libs.versions.toml file when modifying the SDK version name.