From 5d122c3bc83b3a17d52ccc01e29e542316d08c33 Mon Sep 17 00:00:00 2001 From: Colin Edwards Date: Thu, 4 Jan 2024 17:36:58 -0600 Subject: [PATCH] android: Add dependencies and new application class for dagger / hilt support Dagger and hilt give us dependency injection which makes it easier to split up parts of the app. This lets us easily split out things like logging and paves the way to migrate off preferences to DataStore This also remove the process name on the service to pull eveything into one process so we don't have to do IPC to pass logs around. This lets us use the same instances of injected classes between the UI and the service side. --- android/app/build.gradle.kts | 8 +++++++- android/app/src/main/AndroidManifest.xml | 6 +++--- android/app/src/main/java/org/musicpd/MPDApplication.kt | 9 +++++++++ android/build.gradle.kts | 4 +++- 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 android/app/src/main/java/org/musicpd/MPDApplication.kt diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index cb0bb9771..1b88f67f8 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -1,6 +1,8 @@ plugins { id("com.android.application") id("org.jetbrains.kotlin.android") + id("com.google.devtools.ksp") + id("com.google.dagger.hilt.android") } android { @@ -24,7 +26,7 @@ android { } composeOptions { - kotlinCompilerExtensionVersion = "1.5.4" + kotlinCompilerExtensionVersion = "1.5.7" } buildTypes { @@ -64,6 +66,10 @@ dependencies { implementation("com.github.alorma:compose-settings-storage-preferences:1.0.3") implementation("com.google.accompanist:accompanist-permissions:0.33.2-alpha") + implementation("com.google.dagger:hilt-android:2.49") + ksp("com.google.dagger:dagger-compiler:2.49") + ksp("com.google.dagger:hilt-compiler:2.49") + // Android Studio Preview support implementation("androidx.compose.ui:ui-tooling-preview") debugImplementation("androidx.compose.ui:ui-tooling") diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 274c55e64..facfd24ca 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -25,7 +25,8 @@ android:label="@string/app_name" android:requestLegacyExternalStorage="true" android:roundIcon="@mipmap/ic_launcher_round" - android:theme="@style/Theme.MPD"> + android:theme="@style/Theme.MPD" + android:name=".MPDApplication"> @@ -53,8 +54,7 @@ + android:name=".Main" /> diff --git a/android/app/src/main/java/org/musicpd/MPDApplication.kt b/android/app/src/main/java/org/musicpd/MPDApplication.kt new file mode 100644 index 000000000..94d8709cc --- /dev/null +++ b/android/app/src/main/java/org/musicpd/MPDApplication.kt @@ -0,0 +1,9 @@ +package org.musicpd + +import android.app.Application +import dagger.hilt.android.HiltAndroidApp + +@HiltAndroidApp +class MPDApplication : Application() { + +} \ No newline at end of file diff --git a/android/build.gradle.kts b/android/build.gradle.kts index 1b4c7195f..32ac8c304 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -1,5 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id("com.android.application") version "8.1.2" apply false - id("org.jetbrains.kotlin.android") version "1.9.20" apply false + id("org.jetbrains.kotlin.android") version "1.9.21" apply false + id("com.google.devtools.ksp") version "1.9.22-1.0.16" apply false + id("com.google.dagger.hilt.android") version "2.49" apply false } \ No newline at end of file