$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
Kotlin / AndroidintermediateNew

Hilt DI

Share

Set up Hilt dependency injection in Android

Works with OpenClaude

You are an Android developer setting up Hilt dependency injection framework in a Kotlin project. The user wants to configure Hilt, create modules, inject dependencies, and understand the complete setup flow.

What to check first

  • Verify build.gradle.kts (Project level) has the Hilt plugin: id("com.google.dagger.hilt.android") version "2.48" apply false
  • Check that your minSdkVersion is at least 21 in app-level build.gradle.kts

Steps

  1. Add Hilt dependencies to app-level build.gradle.kts under plugins: id("com.google.dagger.hilt.android")
  2. Add Hilt libraries to dependencies: implementation("com.google.dagger:hilt-android:2.48") and kapt("com.google.dagger:hilt-compiler:2.48")
  3. Create an @HiltAndroidApp annotated Application class that extends Application
  4. Declare this Application class in AndroidManifest.xml using the android:name attribute
  5. Create a Hilt module using @Module and @InstallIn annotations to provide dependencies
  6. Use @Provides or @Binds methods within the module to define how to construct instances
  7. Inject dependencies into Activities, Fragments, or Services using @Inject on constructor parameters or properties
  8. Use @Qualifier to distinguish between multiple implementations of the same interface

Code

// Step 1: Application class
package com.example.app

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class MyApplication : Application()

// Step 2: Repository interface and implementation
interface UserRepository {
    fun getUser(id: String): String
}

class UserRepositoryImpl : UserRepository {
    override fun getUser(id: String): String = "User: $id"
}

// Step 3: Hilt Module for providing dependencies
package com.example.app.di

import com.example.app.UserRepository
import com.example.app.UserRepositoryImpl
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class RepositoryModule {
    @Binds
    @Singleton
    abstract fun bindUserRepository(
        impl: UserRepositoryImpl
    ): UserRepository
}

// Alternative: Using @Provides for complex setup
@Module
@InstallIn(SingletonComponent::class)
object ApiModule {
    @Provides
    @Singleton
    fun provideApiService(): ApiService {
        return ApiService("https://api.example.com")

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
kotlinhiltdependency-injection

Install command:

curl -o ~/.claude/skills/kotlin-hilt.md https://clskills.in/skills/kotlin/kotlin-hilt.md

Related Kotlin / Android Skills

Other Claude Code skills in the same category — free to download.

Want a Kotlin / Android skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.