我收到以下错误:
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth
not found
如果我决定在onCompleteListener
内处理身份验证,我的代码可以正常运行,但是当我尝试从FirebaseAuth.AuthStateListener
处理它时,我收到错误。
这是我的登录/注册活动:
public class MainActivity extends AppCompatActivity implements
AdapterView.OnItemSelectedListener {
EditText number;
EditText ans;
TextView questionText;
Spinner country_code;
String[] codes;
String c_code;
Button next_button_1;
ArrayAdapter<String> adapter;
FirebaseAuth mAuth;
FirebaseAuth.AuthStateListener mAuthListener;
Random rand = new Random();
int a = rand.nextInt(10);
int b = rand.nextInt(10);
int c = a+b;
String tes;
String ran2;
String ran1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
codes = new String[] {"+237","+233","+234"};
number = (EditText) findViewById(R.id.editText1);
ans = (EditText) findViewById(R.id.editText_question);
questionText = (TextView) findViewById(R.id.questionText);
ran1 = Integer.toString(a);
ran2 = Integer.toString(b);
tes = Integer.toString(c);
questionText.setText( ran1 + " + " + ran2 + " = ");
country_code = (Spinner) findViewById(R.id.spinner_country_codes);
country_code.setOnItemSelectedListener(this);
adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1,
codes);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
country_code.setAdapter(adapter);
next_button_1 = (Button) findViewById(R.id.sign_in_next_button);
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser() != null) {
FirebaseUser user = firebaseAuth.getCurrentUser();
String uid = user.getUid();
Intent i = new Intent(MainActivity.this,Main2Activity.class);
i.putExtra("uid", uid);
i.putExtra("telephone", number.getText().toString());
i.putExtra("country_code",c_code);
startActivity(i);
}
}
};
if(next_button_1!=null){
next_button_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/*
Intent intent = new Intent(MainActivity.this,
Main2Activity.class);
startActivity(intent);
*/
String answer = ans.getText().toString();
if(answer.equals(tes)) {
String telphone_number = number.getText().toString();
if (TextUtils.isEmpty(c_code) ||
TextUtils.isEmpty(telphone_number)) {
Toast.makeText(MainActivity.this, "Empty field
detected", Toast.LENGTH_SHORT).show();
} else {
String email = c_code + telphone_number +
"mydomain.com";
String password = c_code + telphone_number;
startSignIn(email, password);
}
}else {
a = rand.nextInt(10);
b = rand.nextInt(10);
c = a + b;
ran1 = Integer.toString(a);
ran2 = Integer.toString(b);
tes = Integer.toString(c);
questionText.setText( ran1 + " + " + ran2 + " = ");
Toast.makeText(MainActivity.this, "Your math test answer
is wrong.", Toast.LENGTH_LONG).show();
}
}
});
}
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
String c_code = codes[position].toString();
this.c_code=c_code;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
public void startSignIn(final String e,final String p) {
//Toast.makeText(MainActivity.this, "email is "+ email +" and password
is "+ password + "." , Toast.LENGTH_SHORT).show();
mAuth.signInWithEmailAndPassword(e, p)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>
() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Account not
found.",
Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "Creating a new
Account.",
Toast.LENGTH_LONG).show();
createAccont(e, p);
}
}
});
}
public void createAccont(String e, String p){
mAuth.createUserWithEmailAndPassword(e, p)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>
() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Authentication
Failed",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
我的build.gradle文件如下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion '24.0.3'
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
defaultConfig {
applicationId "biz.batto.mobilemoneymarket"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), '
proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-database:9.6.1'
//compile 'com.google.firebase:firebase-storage:9.6.1'
//compile 'com.google.firebase:firebase-crash:9.6.1'
compile 'com.google.firebase:firebase-auth:9.6.1'
//compile 'com.google.firebase:firebase-messaging:9.6.1'
compile 'com.google.firebase:firebase-config:9.6.1'
compile 'com.google.firebase:firebase-invites:9.6.1'
//compile 'com.google.firebase:firebase-ads:9.6.1'
compile 'com.firebase:firebase-client-android:2.5.2'
compile 'com.firebaseui:firebase-ui:0.6.0'
compile 'com.google.android.gms:play-services-auth:9.6.1'
compile 'com.google.android.gms:play-services-appindexing:9.6.1'
}
apply plugin: 'com.google.gms.google-services'
另外,我想告诉您,我的所有SDK库都是最新的,而且我的AVD上的Google Play服务也是最新的。
在我的MainActivity中,我首先尝试对用户进行身份验证,然后如果失败,我会尝试为您创建一个帐户。当我运行此代码并测试帐户创建过程(或登录过程)时,新帐户实际上是在我的Firebase控制台中创建的,但未通知AuthStateListener
。
因此,我的第二个活动未启动,我的用户用户仍然在同一活动中,而不会导致应用崩溃。我还获得了Android Monitor上的日志:
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
这只在今天开始。我已经在Firebase上进行了一段时间的身份验证,没有任何问题。我该怎么办?
答案 0 :(得分:1)
我遇到了同样的问题,谷歌搜索了一下我认为在gradle上的maven存储库 并将其添加到项目级别gradle
allprojects {
repositories {
// ...
maven { url 'https://maven.fabric.io/public' }
} }
这可以解决问题