google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.44k stars 2.02k forks source link

Dagger 2 / DialogFragment / appcompat-v7:22.2.0 causes "cannot access DialogStyle" #197

Closed jeffdcamp closed 9 years ago

jeffdcamp commented 9 years ago

I don't know if this is an issue with Dagger 2.0 or Android AppCompat....

We are using android.support.v4.app.DialogFragment and Dagger 2. When switching from appcompat-v7:22.1.0 to appcompat-v7:22.2.0 Dagger annotation processor causes the following error:

===== Gradle log ===== :processDebugJavaRes UP-TO-DATE :compileDebugJavaWithJavac error: cannot access DialogStyle class file for android.support.v4.app.DialogFragment$DialogStyle not found Consult the following stack trace for details. com.sun.tools.javac.code.Symbol$CompletionFailure: class file for android.support.v4.app.DialogFragment$DialogStyle not found 1 error :compileDebugJavaWithJavac FAILED

Very Simple Sample Code which causes the error:

===== TestFragment.java ===== import android.support.v4.app.DialogFragment; import org.company.project.Prefs; import javax.inject.Inject;

public class TestFragment extends DialogFragment { @Inject Prefs prefs; }

===== AppComponent.java ===== import org.company.project.ui.TestFragment; import javax.inject.Singleton; import dagger.Component;

@Singleton @Component(modules = AppModule.class) public interface AppComponent { void inject(TestFragment target); }

marcoRS commented 9 years ago

I'm seeing this issue as well :-\

hansenji commented 9 years ago

I am getting the same results with my dialogs.

jeffdcamp commented 9 years ago

It seems that this might be a AppCompat issue... there seems to be similar discussions about this same issue with other annotation processing libraries:

https://github.com/excilys/androidannotations/issues/1435

and

https://code.google.com/p/android/issues/detail?id=175086

jeffdcamp commented 9 years ago

I just found a TEMPORARY workaround... till appcompat fixes this issue:

  1. Create the following package in your project src/main/java

android.support.v4.app

  1. Create the following new file:

DialogFragment$DialogStyle.java

  1. Contents package android.support.v4.app;

// todo remove this file when fixed in appcompat (https://code.google.com/p/android/issues/detail?id=175086) public @interface DialogFragment$DialogStyle { }

marcoRS commented 9 years ago

@jeffdcamp You're proposed solution doesn't seem to work for me I now get the following error:

An exception has occurred in the compiler (1.8.0_40). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you. java.lang.NullPointerException at com.sun.tools.javac.code.Types.eraseNotNeeded(Types.java:2178) at com.sun.tools.javac.code.Types.erasure(Types.java:2171) at com.sun.tools.javac.comp.TransTypes.erasure(TransTypes.java:867) at com.sun.tools.javac.comp.TransTypes.translateClass(TransTypes.java:1018) at com.sun.tools.javac.comp.TransTypes.visitClassDef(TransTypes.java:511) at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693) at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58) at com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:490) at com.sun.tools.javac.comp.TransTypes.translateTopLevelClass(TransTypes.java:1035) at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1486) at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1356) at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860) at com.sun.tools.javac.main.Main.compile(Main.java:523)

jeffdcamp commented 9 years ago

@marcoRS Interesting.... I have applied this work-around to 4 different projects and verified that these projects compile correctly on several machines... I compile with java 8 on one machine and java 7 on another machine....

maxlordks commented 9 years ago

Same issue with @jeffdcamp Is updating jre etc helpful?

RobertoArtiles commented 9 years ago

Getting the same error as @marcoRS

malroy89 commented 9 years ago

+1. Got the same error as @marcoRS

AlexanderThiele commented 9 years ago

same error as @marcoRS

jeffdcamp commented 9 years ago

@marcoRS, @RobertoArtiles, @malroy89 , @AlexanderThiele I found another work-around.... a bit more ugly... but has gotten us around this issue (including the NPE on the above work-around) till appcompat 22.2 is fixed.

android.support.v4.app

https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v4/java/android/support/v4/app/DialogFragment.java

marcoRS commented 9 years ago

@jeffdcamp Thanks for the workaround. I however had to change every class that extended from DialogFragment, not just the classes that used @Inject

floating-cat commented 9 years ago

It was fixed on Android Support 22.2.1.

jeffdcamp commented 9 years ago

Fixed