我想使用Dagger2和Firebase。不幸的是,我收到了以下错误消息:
background_crash E/FA:工作线程上的任务异常: java.lang.IllegalStateException:默认名称的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();
}
}
});
}
}和我的构建文件
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'发布于 2016-08-11 19:14:16
这和匕首没有任何关系。它涉及一个已知的问题,即Firebase崩溃报告,同时使用应用程序子类来处理最终在主进程和崩溃报告创建的进程之间共享的文件或其他资源。人们并不经常讨论Android为应用程序使用的每个进程创建一个新的Application类,在您的例子中,您实际上有两个互相冲突的匕首图。
在本页末尾阅读有关已知问题的文章:https://firebase.google.com/docs/crash/android
最简单的解决方案是要么删除firebase-崩溃依赖项,要么将init逻辑移到内容提供者而不是Application中。无论如何,Android平台团队对应用程序的使用普遍表示不满。
您也可以等到Firebase崩溃报告退出beta版,此时它将不再创建新的流程。
发布于 2016-08-11 14:22:26
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"https://stackoverflow.com/questions/38897115
复制相似问题