Skip to content

Commit 5d6c833

Browse files
committed
fix: configure Dagger Hilt for DI
1 parent acc1163 commit 5d6c833

File tree

13 files changed

+174
-18
lines changed

13 files changed

+174
-18
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ plugins {
3737
alias(libs.plugins.gradle.publish) apply false
3838
alias(libs.plugins.protobuf) apply false
3939
alias(libs.plugins.benchmark) apply false
40+
alias(libs.plugins.hilt) apply false
4041
}
4142

4243
buildscript {

composite-builds/build-logic/plugins/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies {
3737
implementation(projects.buildLogic.propertiesParser)
3838

3939
implementation("com.android.tools.build:gradle:${libs.versions.agp.asProvider().get()}")
40+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlin.asProvider().get()}")
4041
implementation(libs.maven.publish)
4142

4243
implementation(libs.common.jkotlin)

composite-builds/build-logic/plugins/src/main/java/com/itsaky/androidide/plugins/AndroidIDEPlugin.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.itsaky.androidide.plugins
1919

2020
import com.android.build.gradle.BaseExtension
2121
import com.itsaky.androidide.build.config.isFDroidBuild
22+
import com.itsaky.androidide.plugins.util.isAndroidModule
2223
import org.gradle.api.GradleException
2324
import org.gradle.api.Plugin
2425
import org.gradle.api.Project
@@ -39,10 +40,10 @@ class AndroidIDEPlugin : Plugin<Project> {
3940
return@run
4041
}
4142

42-
val isAndroidModule = plugins.hasPlugin("com.android.application") ||
43-
plugins.hasPlugin("com.android.library")
43+
// Apply dependency injection for all modules
44+
plugins.apply(DIConfigPlugin::class.java)
4445

45-
if (isAndroidModule && !isFDroidBuild) {
46+
if (this.isAndroidModule && !isFDroidBuild) {
4647
// setup signing configuration
4748
plugins.apply(SigningConfigPlugin::class.java)
4849
}
@@ -57,7 +58,7 @@ class AndroidIDEPlugin : Plugin<Project> {
5758
}
5859

5960
val taskName = when {
60-
isAndroidModule -> "testDebugUnitTest"
61+
this.isAndroidModule -> "testDebugUnitTest"
6162
else -> "test"
6263
}
6364

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is part of AndroidIDE.
3+
*
4+
* AndroidIDE is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* AndroidIDE is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.itsaky.androidide.plugins
19+
20+
import org.gradle.api.Plugin
21+
import org.gradle.api.Project
22+
23+
/**
24+
* Configures dependency injection in a module.
25+
*
26+
* @author Akash Yadav
27+
*/
28+
class DIConfigPlugin : Plugin<Project> {
29+
30+
override fun apply(target: Project) = target.run {
31+
dependencies.add("implementation", "javax.inject:javax.inject:1")
32+
Unit
33+
}
34+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* This file is part of AndroidIDE.
3+
*
4+
* AndroidIDE is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* AndroidIDE is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.itsaky.androidide.plugins.util
19+
20+
import org.gradle.api.Project
21+
22+
val Project.isAndroidModule: Boolean
23+
get() = isAndroidApplication || isAndroidLibrary
24+
25+
val Project.isAndroidApplication: Boolean
26+
get() = plugins.hasPlugin("com.android.application")
27+
28+
val Project.isAndroidLibrary: Boolean
29+
get() = plugins.hasPlugin("com.android.library")

core/app/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ plugins {
1313
id("realm-android")
1414
id("androidx.navigation.safeargs.kotlin")
1515
id("com.itsaky.androidide.desugaring")
16+
id("com.google.dagger.hilt.android")
1617
}
1718

1819
apply {
@@ -59,6 +60,8 @@ kapt {
5960
arguments {
6061
arg("eventBusIndex", "${BuildConfig.packageName}.events.AppEventsIndex")
6162
}
63+
64+
correctErrorTypes = true
6265
}
6366

6467
desugaring {
@@ -77,6 +80,7 @@ dependencies {
7780
// Annotation processors
7881
kapt(libs.common.glide.ap)
7982
kapt(libs.google.auto.service)
83+
kapt(libs.hilt.compiler)
8084
kapt(projects.annotation.processors)
8185

8286
implementation(libs.common.editor)
@@ -93,6 +97,8 @@ dependencies {
9397
implementation(libs.google.gson)
9498
implementation(libs.google.guava)
9599

100+
implementation(libs.hilt.android)
101+
96102
// Git
97103
implementation(libs.git.jgit)
98104

core/app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ import com.itsaky.androidide.viewmodel.EditorViewModel
102102
import com.itsaky.androidide.xml.resources.ResourceTableRegistry
103103
import com.itsaky.androidide.xml.versions.ApiVersionsRegistry
104104
import com.itsaky.androidide.xml.widgets.WidgetTableRegistry
105+
import dagger.hilt.android.AndroidEntryPoint
105106
import kotlinx.coroutines.CoroutineScope
106107
import kotlinx.coroutines.Dispatchers
107108
import org.greenrobot.eventbus.Subscribe
@@ -118,6 +119,7 @@ import kotlin.math.roundToLong
118119
* @author Akash Yadav
119120
*/
120121
@Suppress("MemberVisibilityCanBePrivate")
122+
@AndroidEntryPoint
121123
abstract class BaseEditorActivity : EdgeToEdgeIDEActivity(), TabLayout.OnTabSelectedListener,
122124
DiagnosticClickListener {
123125

core/app/src/main/java/com/itsaky/androidide/activities/editor/ProjectHandlerActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ abstract class ProjectHandlerActivity : BaseEditorActivity() {
454454

455455
buildServiceConnection.onConnected = null
456456
editorViewModel.isBoundToBuildSerice = true
457-
Lookup.getDefault().update(BuildService.KEY_BUILD_SERVICE, service)
457+
458458
service.setEventListener(mBuildEventListener)
459459

460460
if (!service.isToolingServerStarted()) {

core/app/src/main/java/com/itsaky/androidide/app/IDEApplication.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import com.itsaky.androidide.utils.VMUtils
5858
import com.itsaky.androidide.utils.flashError
5959
import com.termux.app.TermuxApplication
6060
import com.termux.shared.reflection.ReflectionUtils
61+
import dagger.hilt.android.HiltAndroidApp
6162
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
6263
import io.realm.Realm
6364
import kotlinx.coroutines.DelicateCoroutinesApi
@@ -71,7 +72,7 @@ import java.lang.Thread.UncaughtExceptionHandler
7172
import java.time.Duration
7273
import kotlin.system.exitProcess
7374

74-
75+
@HiltAndroidApp
7576
class IDEApplication : TermuxApplication() {
7677

7778
private var uncaughtExceptionHandler: UncaughtExceptionHandler? = null
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* This file is part of AndroidIDE.
3+
*
4+
* AndroidIDE is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* AndroidIDE is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.itsaky.androidide.di
19+
20+
import dagger.Module
21+
import dagger.hilt.InstallIn
22+
import dagger.hilt.android.components.ActivityComponent
23+
24+
/**
25+
* @author Akash Yadav
26+
*/
27+
@Module
28+
@InstallIn(ActivityComponent::class)
29+
abstract class ActivityModule {
30+
}

0 commit comments

Comments
 (0)