Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot resolve symbol DaggerAppComponent #1

Closed
bananaCaptain opened this issue Apr 7, 2016 · 21 comments
Closed

cannot resolve symbol DaggerAppComponent #1

bananaCaptain opened this issue Apr 7, 2016 · 21 comments

Comments

@bananaCaptain
Copy link

component = DaggerAppComponent.builder().appModule(new AppModule(this)).build(); error
@erikjhordan-rey
Copy link
Owner

@bananaCaptain This example works correctly I just checked, Did you try to rebuild the project? You have to go Build -> Rebuild project. Remember that these classes are generated at compile-time.

@IdioticMadman
Copy link
Contributor

@erikcaffrey I am just trying to move the CategoryActivityComponent to another package which does not with the CateoryActivity. And then this error come out . I think you should change this line
https://github.com/erikcaffrey/Dagger2-MVP-Sample/blob/master/app/build.gradle#L38 to "apt 'com.google.dagger:dagger-compiler:2.0'" to suport while those two file doesn't in same package

@erikjhordan-rey
Copy link
Owner

erikjhordan-rey commented Jun 1, 2016

@IdioticMadman the library would not have to be a problem maybe you can try rebuild project, you don't need to create or move another component is just a simple example also there are no many dependencies that must be separated and remember maintain the things simples.

@IdioticMadman
Copy link
Contributor

Yeah, That's OK.Thanks

@dilip90
Copy link

dilip90 commented Dec 20, 2016

@erikcaffrey , thanks rebuild is solution.

@erikjhordan-rey
Copy link
Owner

@aneeshATgithub
Copy link

aneeshATgithub commented Oct 20, 2017

Hello, clean and rebuild is not a solution for me, and the error stays there.

This is my error log:

Error:(8, 47) error: cannot find symbol variable DaggerAppComponent
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.

Can anyone suggest me an alternative or a workaround for this?

@erikjhordan-rey
Copy link
Owner

erikjhordan-rey commented Oct 20, 2017

@aneeshATgithub

The class DaggerAppComponent is a generated class on compile time. Try invalidate caches an restart, and rebuild. if it doesn't works maybe your problem is about version of sdk btw I updated the project to the last version of support library and is working #6

I also have another sample to learn Dagger 2 -> https://github.com/erikcaffrey/Kata-Dagger2-MarioKart

@aneeshATgithub
Copy link

I had tried invalidate caches an restart, also clean and rebuild.
Finally I updated buildToolsVersion to "26.0.2". But the error not gone.

@homandiy
Copy link

Ctrl+F9

@albert0m
Copy link

I had to clean the project and after that I get this error from Studio, even though the files are present. Tried to Invalidate / Restart, Clean, Rebuild.. still get the error from studio.

@homandiy
Copy link

homandiy commented Feb 20, 2018 via email

@albert0m
Copy link

error: cannot find symbol
import com.mypackage.DaggerAppComponent;

I went through most of the answer on stackoverflow but it looks I broke it.

@sandeep287
Copy link

sandeep287 commented May 9, 2018

compile 'com.google.dagger:dagger:2.8'
annotationProcessor 'com.google.dagger:dagger-compiler:2.8'

i will already used this gradle but DaggerAppComponent not support.
please help
thanks in advance

@homandiy
Copy link

homandiy commented May 9, 2018 via email

@erikjhordan-rey
Copy link
Owner

@sandeep287 Hey man!

First of all thanks for visit this repository, I hope you found it useful.

I Upgrated the project some minutes ago and it's working 😃.
imagen
!

Remember the class DaggerAppComponent is a generated class on compile time so you should do:

I hope it solves your problem.

@attifmazhar
Copy link

Invalidate and Restart

@vishalvj9
Copy link

invalidate & cache restart is not valid solution I have started new project setup dagger same problem raise daggerComponent not find the symbols.

@balusreekanth
Copy link

Make Project and Rebuild Project So DaggerAppComponent will be generated .

@freshindee
Copy link

1.Clean the project
2.Rebuild
3.File-->Invalidate and Restart

@homandiy
Copy link

homandiy commented Oct 15, 2019

If you are in test folder, you don't need to rebuild it again; ignore the red line; run it. For example,
fun daggerInjection(app: Application) : TestRetrofitComponent { return DaggerTestRetrofitComponent.builder() .application( app ) .testAppModule(TestAppModule()) // for test purpose: 2 second timeout .apiModule(ApiModule(testUrl, 2, 2)) .build() }
my test component:
`
@singleton
@component(modules = [
AndroidSupportInjectionModule::class,
ApiModule::class,
TestAppModule::class
])
interface TestRetrofitComponent : AppointmentAppComponent {

@Component.Builder
interface Builder {

    @BindsInstance
    fun application(application: Application): Builder

    fun apiModule(apiModule: ApiModule): Builder

    fun testAppModule(testAppModule: TestAppModule): Builder

    fun build(): TestRetrofitComponent // Type
}

// Dagger injector
fun inject(test: MainActivityRetrofitTest)

}

@module
class TestAppModule {
@singleton
@provides
fun giveMockWebServer(): HomanMockWebServer = HomanMockWebServer()
}
Inject to the test class:
@before
fun setUp() {
context = InstrumentationRegistry.getInstrumentation().targetContext
val testApp = context.applicationContext as DebugAppointmentApplication?

    // Dagger component
    val component = daggerInjection(testApp!!)

    testApp.setTestComponent(component)

    // Dagger shot: init all variables
    component.inject(this)

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests