My Experience of Setting up Trixnity Client Dependency in a Kotlin based Android Application Project

Trixnity is a Software Development Kit developed on top of the Matrix Specification for decentralised communication. Trixnity is written in Kotlin and it can be used to add messaging functionality when developing android applications using Kotlin. This article goes over the issues I encountered and fixes I made to solve them while adding Trixnity Client dependency to an Android Studio project.
I am new to Android App development and Kotlin. My wife and I had recently created a project using Android Studio. Messaging capability is needed for the android application we are developing. I was checking out Trixnity for this reason.
I added three Trixnity Client trixnity-client-*
artifacts all having version 4.13.2 to our project after which the project was broken. Later I managed to get the project in good condition with the help of documentations online.
Below were the issues I observed while fixing our project setup.
There was a version conflict in the artifacts of Room Database our project depended on. The project directly depended on a specific version of artifacts for Room Database. Trixnity Client Repository Room internally depended on a different version of Room Database artifacts.
Kotlin Gradle Plugin (KGP) 2.1.0 was required for our project to work after I added the three Trixnity Client artifacts of version 4.13.2. But our project was configured to use KGP 1.9.0.
Our project was configured with Gradle 8.2 and Android Gradle Plugin (AGP) 8.2.1. The version of KGP - 1.9.0 - configured in our project was not compatible with aforementioned Gradle and AGP version according to their officially published compatibility matrix.
Room Database artifacts required KSP instead of KAPT for annotation processing after I upgraded those artifacts for solving issue #1.
Gradle configuration attribute to specify Kotlin Compiler Extension Version became obsolete after I upgraded to KGP version 2.1.0 for solving problem #2 and #3. Official documentation said the Kotlin Compose Plugin had to be applied instead of following the obsolete approach.
Trixnity Client required Ktor engine at runtime. I hadn’t added Ktor engine in our project setup after adding Trixnity Client artifacts.
My attempts to resolve above issues seemingly created inconsistencies in the app installation on my android device used for running the app during development. The app run process from Android Studio was getting stuck with a loading indicator.
Our project got into working condition after fixing above series of issues. Below were the actions I took for fixing our project setup.
Upgraded version of Room Database artifacts defined in our project to match the version of the same artifacts internally used by Trixnity Client Repository Room.
Upgraded KGP to version 2.1.0 as it was required. Upgraded AGP to version 8.2.2 as it was suggested by Android Studio. Verified that the versions specified for Gradle, AGP and KGP in oir project are compatible according to their compatibility matrix.
Migrated to KSP instead of KAPT for annotation processing.
Applied Kotlin Compose Plugin version 2.1.0
Added Ktor Client OkHttp version 3.1.1. This version of Ktor was chosen because it was the latest version available.
Manually uninstalled the broken app installation from my android device used for running the app during development.
Our project was working fine after making above changes and Trixnity Client became usable. I tested the project setup using my Matrix account on matrix.org
public Matrix server. I was able to login to my account programmatically by making use of MatrixClient offered by Trixnity. I was able to pull messages from a Matrix Room to my application’s database and see it in Android Studio’s database inspector.
Snippets from my project setup is attached in the next section of this article. Please keep in mind that the specific actions I took to fix my project setup might not be right for other project setups. My suggestion is to refer official documentation to identify and fix project configuration problems if you are facing any. Links to online sources that helped me to fix my project setup are provided at the end of this article.
Thank you for reading.
Snippets from my Project Setup
The three Trixnity Client dependencies which I added to module level build.gradle.kts
dependencies {
implementation("net.folivo:trixnity-client:4.13.2")
implementation("net.folivo:trixnity-client-media-okio:4.13.2")
implementation("net.folivo:trixnity-client-repository-room:4.13.2")
...
AGP and KGP versions defined in project level build.gradle.kts
plugins {
id("com.android.application") version "8.2.2" apply false
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
}
Gradle and AGP version selected in Android Studio Project Structure
KSP Plugin specified in module level build.gradle.kts
.
plugins {
id("com.google.devtools.ksp") version "2.1.0-1.0.29"
...
Kotlin Compose Plugin specified in module level build.gradle.kts
plugins {
id("org.jetbrains.kotlin.plugin.compose") version "2.1.0"
...
Ktor Client OkHttp specified in module level build.gradle.kts
dependencies {
implementation("io.ktor:ktor-client-okhttp:3.1.1")
...
Links to Online Sources which were Helpful
https://kotlinlang.org/docs/gradle-configure-project.html#apply-the-plugin - has information regarding gradle project configuration and KGP - AGP - Gradle compatibility matrix.
https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html - has information about inspecting dependency tree in gradle.
https://kotlinlang.org/docs/ksp-quickstart.html#add-a-processor - has information about using KSP annotation processor.
https://developer.android.com/jetpack/androidx/releases/compose-kotlin - has information about Compose to Kotlin compatibility.
https://ktor.io/docs/client-engines.html - has information about setting up Ktor OkHttp Client Engine.
https://trixnity.gitlab.io/trixnity/docs/start - has information about Trixnity.
Subscribe to my newsletter
Read articles from Muhammed Salih directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
