Configuration
Gradle
The simple way to apply Tangle is to just apply the gradle plugin. It will automatically add the Anvil plugin and Tangle dependencies.
You can also just add dependencies yourself, without applying the plugin.
Note that Tangle is specifically for Android and has Android-specific dependencies, so it should only be added to Android modules.
- Kotlin Plugin
- Groovy Plugin
- Kotlin Dependencies
- Groovy Dependencies
// settings.gradle.kts
pluginManagement {
repositories {
gradlePluginPortal()
}
}
// root project build.gradle.kts
plugins {
// add Tangle and Anvil versions to the project's classpath
id("com.squareup.anvil") version <anvil_version> apply false
id("com.rickbusarow.tangle") version "0.13.0" apply false
}
// any Android module's build.gradle.kts
plugins {
id("android-library") // or application, etc.
kotlin("android")
id("com.rickbusarow.tangle") version "0.13.1"
}
// optional
tangle {
fragmentsEnabled = true // default is true
workEnabled = true // default is true
viewModelOptions {
enabled = true // default is true
activitiesEnabled = true // default is true
composeEnabled = true // default is false
fragmentsEnabled = true // default is true
}
}
// settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
}
}
// root project build.gradle
plugins {
// add Tangle and Anvil versions to the project's classpath
id 'com.squareup.anvil' version <anvil_version> apply false
id 'com.rickbusarow.tangle' version "0.13.0" apply false
}
// any Android module's build.gradle
plugins {
id 'android-library' // or application, etc.
kotlin("android")
id 'com.rickbusarow.tangle'
}
// optional
tangle {
fragmentsEnabled true // default is true
workEnabled true // default is true
viewModelOptions {
enabled true // default is true
activitiesEnabled true // default is true
composeEnabled true // default is false
fragmentsEnabled true // default is true
}
}
// any Android module's build.gradle.kts
plugins {
id("android-library") // or application, etc.
kotlin("android")
id("com.squareup.anvil")
}
dependencies {
// Fragments
api("com.rickbusarow.tangle:tangle-fragment-api:0.13.1")
anvil("com.rickbusarow.tangle:tangle-fragment-compiler:0.13.1")
// ViewModels
api("com.rickbusarow.tangle:tangle-viewmodel-api:0.13.1")
anvil("com.rickbusarow.tangle:tangle-viewmodel-compiler:0.13.1")
// optional Activity ViewModel support
implementation("com.rickbusarow.tangle:tangle-viewmodel-activity:0.13.1")
// optional Compose ViewModel support
implementation("com.rickbusarow.tangle:tangle-viewmodel-compose:0.13.1")
// optional Fragment ViewModel support
implementation("com.rickbusarow.tangle:tangle-viewmodel-fragment:0.13.1")
// WorkManager
api("com.rickbusarow.tangle:tangle-work-api:0.13.1")
anvil("com.rickbusarow.tangle:tangle-work-compiler:0.13.1")
}
// any Android module's build.gradle
plugins {
id 'android-library' // or application, etc.
kotlin("android")
id 'com.squareup.anvil'
}
dependencies {
// Fragments
api 'com.rickbusarow.tangle:tangle-fragment-api:0.13.1'
anvil 'com.rickbusarow.tangle:tangle-fragment-compiler:0.13.1'
// ViewModels
api 'com.rickbusarow.tangle:tangle-viewmodel-api:0.13.1'
anvil 'com.rickbusarow.tangle:tangle-viewmodel-compiler:0.13.1'
// optional Activity ViewModel support
implementation 'com.rickbusarow.tangle:tangle-viewmodel-activity:0.13.1'
// optional Compose ViewModel support
implementation 'com.rickbusarow.tangle:tangle-viewmodel-compose:0.13.1'
// optional Fragment ViewModel support
implementation 'com.rickbusarow.tangle:tangle-viewmodel-fragment:0.13.1'
// WorkManager
api 'com.rickbusarow.tangle:tangle-work-api:0.13.1'
anvil 'com.rickbusarow.tangle:tangle-work-compiler:0.13.1'
}
Setting up the Tangle graph
In order to connect Tangle to your application-scoped Dagger component,
call TangleGraph.add(...)
immediately after creating the component.
import android.app.Application
import tangle.inject.TangleGraph
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
val myAppComponent = DaggerMyAppComponent.factory()
.create(this)
TangleGraph.add(myAppComponent)
}
}
Next steps
Tangle is now able to generate its code and hook in to Dagger.
Check out these features to start using Tangle in your project: