johncarl81 / transfuse

:syringe: Transfuse - A Dependency Injection and Integration framework for Google Android
http://androidtransfuse.org/
Apache License 2.0
219 stars 28 forks source link

@ObserveEvents not working on services #123

Closed ghost closed 10 years ago

ghost commented 10 years ago

Observing Events doesn't work in services. Could it be that eventtending is missing?

ghost commented 10 years ago

It's not about tending after all. Will have to look further.

ghost commented 10 years ago

Or maybe it is. In Fragments the following code is added, which is missing in Serives:

    @Override
    public void onResume() {
        super.onResume();
        eventTending$$1 .register();
    }

    @Override
    public void onPause() {
        super.onPause();
        eventTending$$1 .unregister();
    }
ghost commented 10 years ago

Btw, same goes for Applications.

johncarl81 commented 10 years ago

@Observes missing is a known bug in @Application components (#98). I'll have to check out @Service components. You can always wire these up yourself in the mean time by using an injected EventManager and the register() method in the @OnResume and @OnPause methods (or equivalent).

ghost commented 10 years ago

This workaround is working fine, thanks for the suggestion.

johncarl81 commented 10 years ago

@airblaster, I believe I've fixed this in version 0.3.0-SNAPSHOT. Could you try this out and let me know about your experience? By the way, this SNAPSHOT is the result of a significant change to the library, so there may be other problems along the way. Either way, let me know.

ghost commented 10 years ago

With snapshot transfuse-0.3.0-20140707.021622-10.jar I get the following error quite a few times:

Exception in thread "pool-184-thread-1" java.lang.NoSuchMethodError: org.androidtransfuse.gen.InstantiationStrategyFactory.buildMethodStrategy(Lcom/sun/codemodel/JBlock;Lcom/sun/codemodel/JExpression;)Lorg/androidtransfuse/gen/MethodInstantiationStrategy;

This seems not to be related to using @Observes in Application/Service classes.

johncarl81 commented 10 years ago

Strange, that error would be the result of an incompatability between the main library and support libraries. Could you try again with: ./gradlew build --refresh dependencies to make sure you have the latest SNAPSHOT?

johncarl81 commented 10 years ago

Ah, I just thought of this... this may be caused by using an earlier version of Parceler with this version of Transfuse, since they both share a common core. Please use Parceler version 0.2.11-SNAPSHOT as well.

ghost commented 10 years ago

Unfortunately the same error appears with Parceler version 0.2.11-SNAPSHOT.

johncarl81 commented 10 years ago

can you tell me what exact SNAPSHOT versions you're using of transfuse-core and transfuse-support?

ghost commented 10 years ago

How can I figure this out? Android Studio doesn't seem to show it. gradle :app:depenedencies shows the following for apt:

apt
+--- org.androidtransfuse:transfuse:0.3.0-SNAPSHOT
|    +--- org.androidtransfuse:transfuse-bootstrap:0.3.0-SNAPSHOT
|    |    \--- org.androidtransfuse:transfuse-core:0.3.0-SNAPSHOT
|    |         +--- org.androidtransfuse:transfuse-support:0.3.0-SNAPSHOT
|    |         |    +--- org.androidtransfuse:transfuse-api:0.3.0-SNAPSHOT
|    |         |    |    +--- javax.inject:javax.inject:1
|    |         |    |    \--- aopalliance:aopalliance:1.0
|    |         |    +--- com.google.guava:guava:15.0
|    |         |    +--- javax.inject:javax.inject:1
|    |         |    +--- com.google.code.findbugs:jsr305:2.0.3
|    |         |    +--- commons-lang:commons-lang:2.6
|    |         |    \--- com.sun.codemodel:codemodel:2.6
|    |         \--- commons-beanutils:commons-beanutils:1.9.0
|    |              +--- commons-logging:commons-logging:1.1.1
|    |              \--- commons-collections:commons-collections:3.2.1
|    +--- org.parceler:parceler-api:0.2.5 -> 0.2.11-SNAPSHOT
|    \--- com.sun.xml.bind:jaxb-impl:2.2.8-b01
|         +--- com.sun.xml.bind:jaxb-core:2.2.8-b01
|         |    +--- javax.xml.bind:jaxb-api:2.2.9
|         |    \--- com.sun.istack:istack-commons-runtime:2.16
|         \--- com.sun.xml.fastinfoset:FastInfoset:1.2.12
|              \--- javax.xml.bind:jsr173_api:1.0
+--- org.parceler:parceler:0.2.11-SNAPSHOT
|    +--- org.parceler:parceler-api:0.2.11-SNAPSHOT
|    \--- org.androidtransfuse:transfuse-bootstrap:0.3.0-SNAPSHOT (*)
+--- com.github.frankiesardo:icepick-processor:2.3.5
|    +--- com.github.frankiesardo:icepick:2.3.5
|    \--- com.google.guava:guava:15.0
+--- com.google.android:android:2.1_r1
|    +--- commons-logging:commons-logging:1.1.1
|    +--- org.apache.httpcomponents:httpclient:4.0.1
|    |    +--- org.apache.httpcomponents:httpcore:4.0.1
|    |    +--- commons-logging:commons-logging:1.1.1
|    |    \--- commons-codec:commons-codec:1.3
|    +--- org.khronos:opengl-api:gl1.1-android-2.1_r1
|    +--- xerces:xmlParserAPIs:2.6.2
|    \--- xpp3:xpp3:1.1.4c
+--- com.android.support:support-v4:19.1.0
+--- com.android.support:appcompat-v7:19.1.0
|    \--- com.android.support:support-v4:19.1.0
+--- :ormdroid:
+--- com.squareup.retrofit:retrofit:1.5.1
|    \--- com.google.code.gson:gson:2.2.4
+--- com.twotoasters.jazzylistview:library:1.0.1
|    +--- com.nineoldandroids:library:2.4.0
|    \--- com.android.support:support-v4:19.0.0 -> 19.1.0
+--- uk.co.ribot:easyadapter:1.0.1
+--- com.squareup.okhttp:okhttp:1.5.4
+--- com.squareup.picasso:picasso:2.2.0
+--- com.dobmob.doblist:lib:1.1.1-SNAPSHOT
+--- mobi.parchment:parchment:1.6.7
+--- org.androidtransfuse:transfuse-api:0.3.0-SNAPSHOT (*)
+--- org.parceler:parceler-api:0.2.11-SNAPSHOT
+--- com.github.frankiesardo:icepick:2.3.5
\--- com.astuetz:pagerslidingtabstrip:1.0.1
     \--- com.android.support:support-v4:19.0.0 -> 19.1.0

What seems strange to me is the following dependency for org.androidtransfuse:transfuse:0.3.0-SNAPSHOT

org.parceler:parceler-api:0.2.5 -> 0.2.11-SNAPSHOT
johncarl81 commented 10 years ago

Everything looks in order. Can you try another build with ./gradlew build --refresh dependencies to make sure the SNAPSHOTs are all up to date?

ghost commented 10 years ago

Deleted gradle cache files and it seems I'm on the new snapshot now. Still getting a compile error, though: In one of my generated Fragment files "view$$1" is declared locally in onCreateView. onCreate assumes it can access "view$$1", which isn't the case - resulting in an "Error:(88, 40) error: cannot find symbol variable view$$1" error.

EDIT: onCreate seems to be only containing code that registers @Observes listeners

johncarl81 commented 10 years ago

Ah, I found the problem... will push a new SNAPSHOT this afternoon.

ghost commented 10 years ago

Thats good news, looking forward to the new snapshot

johncarl81 commented 10 years ago

@airblaster, give 0.3.0-SNAPSHOT another try, just pushed out a fix for that issue.

ghost commented 10 years ago

@johncarl81, I tried compiling the component_generation branch, but get loads of Unit-Test errors on the final "transfuse" module.

johncarl81 commented 10 years ago

Strange, especially because Travis builds it without error: https://travis-ci.org/johncarl81/transfuse/builds/29941148

What errors are you seeing? Can you try the SNAPSHOT in Maven central?

ghost commented 10 years ago

Just tested observing Events in Application, it works :) Regarding the errors, can I send you the surefire-reports by mail? Though it might be just me doing something wrong.

johncarl81 commented 10 years ago

Awesome news! Yeah, can you email me the output?