RBusarow
Tangle
Kotlin

Android injection using the Anvil compiler plugin

Last updated Apr 20, 2026
88
Stars
9
Forks
25
Issues
0
Stars/day
Attention Score
17
Language breakdown
No language data available.
โ–ธ Files click to expand
README

Maven Central Gradle Plugin Portal License


Tangle creates [Dagger] bindings for Android classes using the [Anvil] Kotlin compiler plugin. This is meant to be an alternative to [Hilt], for those who'd prefer to enjoy the faster compilation and better flexibility of Anvil.

Since Tangle is an extension upon Anvil, its code generation will be applied to Kotlin files only.

Please see the project website for full documentation.

Features

ViewModel Injection

class MyViewModel @VMInject constructor(
  val repository: MyRepository,
  @TangleParam("userId") // pulls the "userId" argument out of SavedStateHandle
  val userId: String
) : ViewModel()

@Composable fun MyComposable( navController: NavController, viewModel: MyViewModel = tangleViewModel() ) { / ... / }

class MyFragment : Fragment() { val viewModel: MyViewModel by tangleViewModel() }

Inject ViewModels, including scoped SavedStateHandle arguments. Use the @TangleParam annotation to automatically extract navigation/Bundle arguments and inject them directly. read more

Fragment Injection with Bundle arguments

@ContributesFragment(AppScope::class)
class MyFragment @FragmentInject constructor(
  val repository: MyRepository
) : Fragment() {

val name: String by arg("name")

@FragmentInjectFactory interface Factory { fun create( @TangleParam("name") name: String ): MyFragment } }

Use constructor injection in Fragments, with optional AssistedInject-like factories for type-safe Bundle arguments. Bindings are created automatically. read more

Worker Injection

@TangleWorker
class MyWorker @AssistedInject constructor(
  @Assisted context: Context,
  @Assisted params: WorkerParameters
) : CoroutineWorker(context,params) {
  override suspend fun doWork(): Result {
    / ... /
  }
}

Use Dagger's @AssistedInject and @Assisted annotations and @TangleWorker to inject any ListenableWorker. read more

License

text
Copyright (C) 2021 Rick Busarow
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
     http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

[Anvil]: https://github.com/square/anvil

[Dagger]: https://dagger.dev

[Hilt]: https://dagger.dev/hilt/view-model.html

[SavedStateHandle]: https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate

ยฉ 2026 GitRepoTrend ยท RBusarow/Tangle ยท Updated daily from GitHub