0
votes

I want to use Dagger2 and Firebase. Unfortunately i'm getting the following error message:

background_crash E/FA: Task exception on worker thread: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.

If i do not use Dagger2 everything works fine. Whats wrong here? Do i have to init the FirebaseApp manually? Thanks! Here is my code:

// App extends Application
@Override
public void onCreate() {
    super.onCreate();
    appComponent = DaggerAppComponent
            .builder()
            .appModule(new AppModule(this))
            .build();
    firebaseAnalytics = FirebaseAnalytics.getInstance(this);
}

...

// AppComponent.class
@Provides
@Singleton
public FirebaseAuth provideFirebaseAuth() {
    return FirebaseAuth.getInstance();
}

...

@ActivityScope
@Component(dependencies = AppComponent.class)
public interface SignupComponent {
    void inject(SignupActivity signupActivity);
}

...

@Inject
public FirebaseAuth firebaseAuth;

private SignupComponent signupComponent;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);
    ButterKnife.bind(this);
    signupComponent = DaggerSignupComponent
            .builder()
            .appComponent(((App)getApplication()).getAppComponent())
            .build();
    signupComponent.inject(this);
}

@OnClick(R.id.sign_up_btn_sign_up)
public void clickOnSignUp() {
    String email = emailInput.getText().toString();
    String pass = passwordInput.getText().toString();

    if (!TextUtils.isEmpty(email) && !TextUtils.isEmpty(pass)) {
        progressBar.setVisibility(View.VISIBLE);
        firebaseAuth.createUserWithEmailAndPassword(email, pass)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        progressBar.setVisibility(View.GONE);
                        if (task.isSuccessful()) {
                            Toast.makeText(SignupActivity.this, "yeppppa", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }
}

Aaaand my build file

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:cardview-v7:24.1.1'
    compile 'com.android.support:recyclerview-v7:24.1.1'

    compile 'com.google.firebase:firebase-core:9.4.0'
    compile 'com.google.firebase:firebase-database:9.4.0'
    compile 'com.google.firebase:firebase-storage:9.4.0'
    compile 'com.google.firebase:firebase-crash:9.4.0'
    compile 'com.google.firebase:firebase-auth:9.4.0'

    compile 'com.google.dagger:dagger:2.6'
    apt 'com.google.dagger:dagger-compiler:2.6'

    compile 'com.jakewharton:butterknife:8.2.1'
    apt 'com.jakewharton:butterknife-compiler:8.2.1'
}

apply plugin: 'com.google.gms.google-services'
2
Did you add "compile 'com.google.firebase:firebase-auth:9.4.0'" in your app level build.gradle file ? - Ketan Mehta
@KetanMehta yes i did. Please see my post. I added my build file. - Tobias
Did you enable the sign in method in firebase console ? @Tobias - Ketan Mehta
Yep. As i wrote. Everything works fine if i do not use Dagger. Without Dagger i can save, edit and delete my users. - Tobias
Hey @tobias i have the same problem but i fixed the problem same as urs adding name to firebase, but now i have another problem that firebase should be generated any luck on ur side? - Spurdow

2 Answers

2
votes

This actually doesn't have anything to do with Dagger. It has to do with a known issue with Firebase Crash Reporting alongside use of an Application subclass that deals with files or other resources that end up being shared between the main process and the process that Crash Reporting creates. It's not often discussed that Android creates a new Application class for each process your app uses, and in your case, you effectively have two Dagger graphs that are conflicting with each other.

Read about the known problem at the end of this page: https://firebase.google.com/docs/crash/android

The easiest solution would be to either remove the firebase-crash dependency, or move your init logic into a Content Provider instead of Application. Use of Application is generally frowned upon by the Android platform team anyway.

You can also wait until Firebase Crash Reporting leaves beta, at which point it will no longer create a new process.

0
votes
 wrong configured dagger-compiler:

compile 'com.google.dagger:dagger-compiler:2.1'

please modify project level ' build.gradle:

buildscript 
{
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}
And then app level build.gradle:

First, add plugin:

apply plugin: 'com.neenbedankt.android-apt'

And then modify the dependency to

apt "com.google.dagger:dagger-compiler:2.1"