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

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

Closed
jeffdcamp opened this issue May 28, 2015 · 14 comments

Comments

@jeffdcamp
Copy link

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
Copy link

marcoRS commented May 29, 2015

I'm seeing this issue as well :-\

@hansenji
Copy link

I am getting the same results with my dialogs.

@jeffdcamp
Copy link
Author

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

androidannotations/androidannotations#1435

and

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

@jeffdcamp
Copy link
Author

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
Copy link

marcoRS commented May 29, 2015

@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
Copy link
Author

@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
Copy link

Same issue with @jeffdcamp Is updating jre etc helpful?

@RobertoArtiles
Copy link

Getting the same error as @marcoRS

@malroy89
Copy link

malroy89 commented Jun 1, 2015

+1. Got the same error as @marcoRS

@AlexanderThiele
Copy link

same error as @marcoRS

@jeffdcamp
Copy link
Author

@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.

  • Create the following package in your project src/main/java

android.support.v4.app

  • Copy the Google v4 FragmentDialog.java code

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

  • Rename the class (to something like TempFragmentDialog). You will get a "Duplicate" class error if you don't rename the class.
  • Any FragmentDialog, in your project, that has @Inject will need to extend your copy of the FragmentDialog (example: public class MyFragmentDialog extends TempFragmentDialog)

@marcoRS
Copy link

marcoRS commented Jun 2, 2015

@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
Copy link

It was fixed on Android Support 22.2.1.

@jeffdcamp
Copy link
Author

Fixed

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

8 participants