我想使用 Dagger2 和 Firebase。不幸的是,我收到以下错误消息:
background_crash E/FA:工作线程上的任务异常:java.lang.IllegalStateException:名称为 [DEFAULT] 的 FirebaseApp 不存在。
W/DynamiteModule:未找到 com.google.firebase.auth 的本地模块描述符类。
如果我不使用 Dagger2 一切正常。这里有什么问题?我必须FirebaseApp
手动初始化吗?谢谢!这是我的代码:
// 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();
}
}
});
}
}
Aaa和我的构建文件
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'