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'