Colton Idle
07/21/2023, 3:34 PM@Singleton
or is putting it in SingletonComponent good enough?
@InstallIn(SingletonComponent::class)
@Module
class AppModule {
@Provides
fun provideMoshi(): Moshi {
return Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
}
}
Colton Idle
07/25/2023, 9:28 PMclass Bar @Inject constructor (random: Thing)
and I don't need a provides method (except for Thing)
. Everything is good.
Now whats the best way to make Bar an interface?
interface Bar
class ConcreteBar @Inject constructor (randomButOnlyNeededForConcreteImpl: Thing): Bar
I have this provides statement, and it works... but kinda annoying to repeat the injection params since I am already doing it at the class with the @Inject annotation. Am I doing something wrong?
@Provides
@Singleton
fun provideBar(
randomButOnlyNeededForConcreteImpl: Thing)
): Bar {
return ConcreteBar(randomButOnlyNeededForConcreteImpl)
}
Colton Idle
07/27/2023, 12:19 AM@InstallIn(SingletonComponent::class)
@Module
class AppModuleProviders {
...
}
@Module
@InstallIn(SingletonComponent::class)
interface AppModuleBinders {
...
}
kotlinforandroid
08/06/2023, 10:31 AMApplication
classes, one for main
and one for debug
sourceSet. However, hilt complains during compilation that I cannot have multiple app roots: Cannot process multiple app roots in the same compilation unit
. How can I solve this issue?
I use a simple manifest to replace the class used:
<manifest xmlns:android="<http://schemas.android.com/apk/res/android>"
xmlns:tools="<http://schemas.android.com/tools>">
<application
tools:replace="android:name"
android:name=".DebugApplication"/>
</manifest>
Manuel Vivo
08/30/2023, 4:30 PMColton Idle
08/31/2023, 12:38 AMid "com.google.devtools.ksp" version "1.9.0-1.0.12"
trevjones
09/04/2023, 6:59 PMval useKsp: String by project
if(useKsp.toBooleanStrict()) {
apply(plugin = "com.google.devtools.ksp")
dependencies {
implementation(libs.dagger)
"ksp"(libs.dagger.compiler)
"kspTest"(libs.dagger.compiler)
}
} else {
apply(plugin = "org.jetbrains.kotlin.kapt")
dependencies {
implementation(libs.dagger)
"kapt"(libs.dagger.compiler)
"kaptTest"(libs.dagger.compiler)
}
}
ursus
09/06/2023, 2:12 PM...:compileWithJavac
Cannot find symbol FooModule_XYZFactory
cant pinpoint if its dagger or anvil causing this ..Håkon Pettersen
09/07/2023, 5:26 PM[ksp] Cannot use legacy dagger.spi.BindingGraphPlugin while compiling with KSP: Dagger/Android/DuplicateAndroidInjectors. Either compile with KAPT or migrate the plugin to implement dagger.spi.model.BindingGraphPlugin.
Anyone familiar with this issue?abbic
09/26/2023, 10:33 AM@Singleton
class EventBus<T> @Inject constructor() {
Daniel Perez
09/28/2023, 12:05 AMBrais Gabin
10/06/2023, 11:00 AMjw
10/06/2023, 11:07 AMjw
10/06/2023, 11:09 AMMehmet
10/30/2023, 5:18 PM@Component(
dependencies = [ChildComponent::class],
modules = [RootModule::class]
)
interface RootComponent {
val myClass: MyClass
}
@Module
interface RootModule {
companion object {
@[Provides IntoSet]
fun name(): String = "Root"
}
}
class MyClass @Inject constructor(names: Set<String>) {
init {
//java.lang.AssertionError: names only has [Root]
assert(names == setOf("Root", "Child")) { "names only has $names" }
}
I tried below approaches for the child component:
//Try 1: Compiles but "Child" is not injected in RootComponent. Which makes sense because "ChildComponent" doesn't expose it.
@Component(modules = [ChildModule::class])
interface ChildComponent {
}
@Module
interface ChildModule {
companion object {
@[Provides IntoSet]
fun name(): String = "Child"
}
}
//Try 2: compile-time-error: "String cannot be provided without an @Inject constructor or an @Provides-annotated method" It makes sense because there is no provider for `String` type in ChildComponent. IntoSet annotation in ChildModule provides Set<String> type.
@Component(modules = [ChildModule::class])
interface ChildComponent {
val name: String
}
@Module
interface ChildModule {
companion object {
@[Provides IntoSet]
fun name(): String = "Child"
}
}
//Try 3: Compile-time-error "[Dagger/DuplicateBindings] Set<String> has incompatible bindings or declarations in RootComponent". Now we have two bindings with type Set<String> one is coming from ChildComponent and the other from RootComponent
@Component(modules = [ChildModule::class])
interface ChildComponent {
val names: Set<String>
}
@Module
interface ChildModule {
companion object {
@[Provides IntoSet]
fun name(): String = "Child"
}
}
// Try 4: Compile time error "@Binds methods can only be present within a @Module or @ProducerModule"
@Component(modules = [ChildModule::class])
interface ChildComponent {
@get:[Binds IntoSet]
val name: String
}
@Module
interface ChildModule {
companion object {
@Provides
fun name(): String = "Child"
}
}
I’m not sure if what I want is achievable at all. Any help/idea is appreciated.myanmarking
11/02/2023, 3:56 PMdave08
11/08/2023, 1:58 PM@AndroidEntryPoint
to a broadcast receiver, and I seem to be getting the error I posted in the thread, I tried looking around in Google, but to no avail... is this a known issue? Is there a workaround?dave08
11/08/2023, 4:19 PMUnable to load class 'com.google.devtools.ksp.gradle.KspTaskJvm'
com.google.devtools.ksp.gradle.KspTaskJvm
Lubomir Pisk
11/09/2023, 8:33 AMPeter
11/22/2023, 8:05 PMBrais Gabin
12/01/2023, 11:10 AM@Provides
were the only reference to a lot of dead classes (and its dependencies). Give it a try and give us feedback! https://github.com/SchwarzIT/dagger-lightsaberGaurav
12/06/2023, 6:22 AMA failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
> java.lang.reflect.InvocationTargetException (no error message)
Full log ->trevjones
12/06/2023, 7:18 PMMohammed Akram Hussain
12/07/2023, 2:58 PMgts13
01/07/2024, 2:17 PMinterface ManagerProxy {
fun execute()
}
class Manager() : ManagerProxy {
override fun execute() { // do something }
fun otherExecute() { // do something else }
}
class ClientOne @Inject constructor(
private val manager: Manager
) {
mananager.otherExecute()
...
}
class ClientTwo @Inject constructor(
private val managerProxy: ManagerProxy // need to have the same instance of Manager from ClientOne
) {
mananager.execute()
...
}
galex
01/30/2024, 2:04 PMlaunchInHiltContainer
from the architecture-samples
with ViewModels that have an @AssistedFactory ?galex
02/05/2024, 4:58 AMDaniel Souza Bertoldi
02/11/2024, 3:18 PMBookStoreNotesApplication_HiltComponents.ViewModelC repeats modules with scoped bindings or declarations:
More details in thread!vide
03/11/2024, 3:11 PMBaseApplication
and when I remove the last injection, I get this when compiling tests:
Cannot process test roots and app roots in the same compilation unit:
App root in this compilation unit: vide.BaseApplication
Test roots in this compilation unit: [vide.Test1, vide.Test2, ...]
rkeazor
03/19/2024, 12:20 AM