erikjhordan-rey / Dagger2-MVP-Sample

Android Sample to explain Dagger 2 and MVP in android applications.
https://erikjhordan-rey.github.io/blog/2016/04/25/ANDROID-dependency-injection.html
108 stars 34 forks source link

cannot resolve symbol DaggerAppComponent #1

Closed bananaCaptain closed 7 years ago

bananaCaptain commented 8 years ago
component = DaggerAppComponent.builder().appModule(new AppModule(this)).build(); error
erikjhordan-rey commented 8 years ago

@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 commented 8 years ago

@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 commented 8 years ago

@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 commented 8 years ago

Yeah, That's OK.Thanks

dilip90 commented 7 years ago

@erikcaffrey , thanks rebuild is solution.

erikjhordan-rey commented 7 years ago

@dilip90 @IdioticMadman @bananaCaptain https://erikcaffrey.github.io/ANDROID-kata-dagger2/

aneeshATgithub commented 7 years ago

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 commented 7 years ago

@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 https://github.com/erikcaffrey/Dagger2-MVP-Sample/pull/6

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

aneeshATgithub commented 7 years ago

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 commented 6 years ago

Ctrl+F9

albert0m commented 6 years ago

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 commented 6 years ago

What's error?

On Tue, Feb 20, 2018 at 6:58 AM, marconealberto notifications@github.com wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/erikcaffrey/Dagger2-MVP-Sample/issues/1#issuecomment-367003739, or mute the thread https://github.com/notifications/unsubscribe-auth/AbZG7u3O8QysBxH46mWuA6oH4nwAnAxVks5tWt15gaJpZM4IBtEs .

albert0m commented 6 years ago
error: cannot find symbol
import com.mypackage.DaggerAppComponent;

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

sandeep287 commented 6 years ago

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 commented 6 years ago

Where is your project address at Github? Let me try.

Homan Huang

On Wed, May 9, 2018 at 4:36 AM, sandeep287 notifications@github.com wrote:

compile "com.google.dagger🗡$daggerversion" annotationProcessor "com.google.dagger:dagger-compiler:$daggerversion"

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/erikcaffrey/Dagger2-MVP-Sample/issues/1#issuecomment-387710519, or mute the thread https://github.com/notifications/unsubscribe-auth/AbZG7s3R5RW2F4yxaFivPeGrnHCh_xf2ks5twtTNgaJpZM4IBtEs .

erikjhordan-rey commented 6 years ago

@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 commented 5 years ago

Invalidate and Restart

vishalvj9 commented 5 years ago

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

balusreekanth commented 5 years ago

Make Project and Rebuild Project So DaggerAppComponent will be generated .

freshindee commented 5 years ago

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

homandiy commented 5 years ago

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)

`