Skip to content

Commit d2cc37a

Browse files
committed
Added daggerhilt for better dependency injection for Compose Viewmodels
1 parent 5062d38 commit d2cc37a

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

app/build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins {
99
id "kotlin-parcelize"
1010
id "checkstyle"
1111
id "org.sonarqube" version "4.0.0.2929"
12+
id "dagger.hilt.android.plugin"
1213
}
1314

1415
android {
@@ -122,6 +123,8 @@ ext {
122123
googleAutoServiceVersion = '1.1.1'
123124
groupieVersion = '2.10.1'
124125
markwonVersion = '4.6.2'
126+
hiltVersion = '1.2.0'
127+
daggerVersion = '2.51.1'
125128

126129
leakCanaryVersion = '2.12'
127130
stethoVersion = '1.6.0'
@@ -203,7 +206,7 @@ dependencies {
203206
// name and the commit hash with the commit hash of the (pushed) commit you want to test
204207
// This works thanks to JitPack: https://jitpack.io/
205208
implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751'
206-
implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.24.0'
209+
implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.24.2'
207210
implementation 'com.github.TeamNewPipe:NoNonsense-FilePicker:5.0.0'
208211

209212
/** Checkstyle **/
@@ -295,6 +298,14 @@ dependencies {
295298
implementation 'androidx.activity:activity-compose'
296299
implementation 'androidx.compose.ui:ui-tooling-preview'
297300

301+
// hilt
302+
implementation("androidx.hilt:hilt-navigation-compose:${hiltVersion}")
303+
kapt("androidx.hilt:hilt-compiler:${hiltVersion}")
304+
305+
// dagger
306+
implementation("com.google.dagger:hilt-android:${daggerVersion}")
307+
kapt("com.google.dagger:hilt-android-compiler:${daggerVersion}")
308+
298309
/** Debugging **/
299310
// Memory leak detection
300311
debugImplementation "com.squareup.leakcanary:leakcanary-object-watcher-android:${leakCanaryVersion}"
@@ -315,6 +326,10 @@ dependencies {
315326
androidTestImplementation "androidx.test:runner:1.5.2"
316327
androidTestImplementation "androidx.room:room-testing:${androidxRoomVersion}"
317328
androidTestImplementation "org.assertj:assertj-core:3.24.2"
329+
330+
// dagger
331+
testImplementation("com.google.dagger:hilt-android-testing${daggerVersion}")
332+
androidTestImplementation("com.google.dagger:hilt-android-testing${daggerVersion}")
318333
}
319334

320335
static String getGitWorkingBranch() {

app/src/main/java/org/schabi/newpipe/App.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.List;
3333
import java.util.Objects;
3434

35+
import dagger.hilt.android.HiltAndroidApp;
3536
import io.reactivex.rxjava3.exceptions.CompositeException;
3637
import io.reactivex.rxjava3.exceptions.MissingBackpressureException;
3738
import io.reactivex.rxjava3.exceptions.OnErrorNotImplementedException;
@@ -57,6 +58,7 @@
5758
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
5859
*/
5960

61+
@HiltAndroidApp
6062
public class App extends Application {
6163
public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID;
6264
private static final String TAG = App.class.toString();

build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
buildscript {
44
ext.kotlin_version = '1.9.10'
5+
ext.dagger_version ='2.51.1'
56
repositories {
67
google()
78
mavenCentral()
89
}
910
dependencies {
10-
classpath 'com.android.tools.build:gradle:8.2.0'
11+
classpath 'com.android.tools.build:gradle:8.5.1'
1112
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12-
13+
classpath("com.google.dagger:hilt-android-gradle-plugin:$dagger_version")
1314
// NOTE: Do not place your application dependencies here; they belong
1415
// in the individual module build.gradle files
1516
}
@@ -19,6 +20,7 @@ allprojects {
1920
repositories {
2021
google()
2122
mavenCentral()
23+
gradlePluginPortal()
2224
maven { url "https://jitpack.io" }
2325
maven { url "https://repo.clojars.org" }
2426
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
distributionSha256Sum=38f66cd6eef217b4c35855bb11ea4e9fbc53594ccccb5fb82dfd317ef8c2c5a3
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
55
networkTimeout=10000
66
zipStoreBase=GRADLE_USER_HOME
77
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)