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.
This commit is contained in:
Colin Edwards 2024-01-04 17:36:58 -06:00
parent d0a4270449
commit 5d122c3bc8
4 changed files with 22 additions and 5 deletions

View File

@ -1,6 +1,8 @@
plugins { plugins {
id("com.android.application") id("com.android.application")
id("org.jetbrains.kotlin.android") id("org.jetbrains.kotlin.android")
id("com.google.devtools.ksp")
id("com.google.dagger.hilt.android")
} }
android { android {
@ -24,7 +26,7 @@ android {
} }
composeOptions { composeOptions {
kotlinCompilerExtensionVersion = "1.5.4" kotlinCompilerExtensionVersion = "1.5.7"
} }
buildTypes { buildTypes {
@ -64,6 +66,10 @@ dependencies {
implementation("com.github.alorma:compose-settings-storage-preferences:1.0.3") implementation("com.github.alorma:compose-settings-storage-preferences:1.0.3")
implementation("com.google.accompanist:accompanist-permissions:0.33.2-alpha") 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 // Android Studio Preview support
implementation("androidx.compose.ui:ui-tooling-preview") implementation("androidx.compose.ui:ui-tooling-preview")
debugImplementation("androidx.compose.ui:ui-tooling") debugImplementation("androidx.compose.ui:ui-tooling")

View File

@ -25,7 +25,8 @@
android:label="@string/app_name" android:label="@string/app_name"
android:requestLegacyExternalStorage="true" android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/Theme.MPD"> android:theme="@style/Theme.MPD"
android:name=".MPDApplication">
<activity <activity
android:name=".ui.SettingsActivity" android:name=".ui.SettingsActivity"
android:exported="true"> android:exported="true">
@ -53,8 +54,7 @@
</receiver> </receiver>
<service <service
android:name=".Main" android:name=".Main" />
android:process=":main" />
</application> </application>
</manifest> </manifest>

View File

@ -0,0 +1,9 @@
package org.musicpd
import android.app.Application
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class MPDApplication : Application() {
}

View File

@ -1,5 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins { plugins {
id("com.android.application") version "8.1.2" apply false 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
} }