我在https://github.com/firebase/quickstart-android/tree/master/database跟踪了示例代码实时数据库 一切都可以在调试模式下找到。但是,如果我安装签名的apk,从谷歌播放下载,将构建变体从调试更改为在android studio中发布。登录将崩溃。
我已经获得了发布的SHA1并相应地更新了json文件。
我观察到了这一点,不知道是否相关。 如果我使用调试模式成功登录,数据库将会更改 在发布模式下,更改不会出现在数据库控制台中
这 A: “test@gmail.com” b: “测试”
到
电子邮件: “test@gmail.com” 用户名: “测试” 错误logcat
E/AndroidRuntime: FATAL EXCEPTION: main
Process: simonhcm.multiplay, PID: 18928
java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]
at com.a.a.a.d.a(Unknown Source)
at android.support.v7.widget.ek.b(Unknown Source)
at android.support.v7.widget.fb.a(Unknown Source)
at android.support.v7.widget.fb.c(Unknown Source)
at android.support.v7.widget.dj.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.c(Unknown Source)
at android.support.v7.widget.RecyclerView.J(Unknown Source)
at android.support.v7.widget.RecyclerView.k(Unknown Source)
at android.support.v7.widget.RecyclerView.t(Unknown Source)
at android.support.v7.widget.RecyclerView.c(Unknown Source)
at android.support.v7.widget.ee.run(Unknown Source)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:603)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NoSuchMethodException: <init> [class android.view.View]
at java.lang.Class.getConstructor(Class.java:528)
at java.lang.Class.getConstructor(Class.java:492)
at com.a.a.a.d.a(Unknown Source)
at android.support.v7.widget.ek.b(Unknown Source)
at android.support.v7.widget.fb.a(Unknown Source)
at android.support.v7.widget.fb.c(Unknown Source)
at android.support.v7.widget.dj.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.c(Unknown Source)
at android.support.v7.widget.RecyclerView.J(Unknown Source)
at android.support.v7.widget.RecyclerView.k(Unknown Source)
at android.support.v7.widget.RecyclerView.t(Unknown Source)
at android.support.v7.widget.RecyclerView.c(Unknown Source)
at android.support.v7.widget.ee.run(Unknown Source)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:603)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
W/ActivityManager: Force finishing activity simonhcm.multiplay/.MainActivity
W/DropBoxManagerService: Dropping: data_app_crash (1883 > 0 bytes)
I/OpenGLRenderer: Initialized EGL, version 1.4
I/art: Background partial concurrent mark sweep GC freed 6907(456KB) AllocSpace objects, 1(20KB) LOS objects, 28% free, 41MB/57MB, paused 1.419ms total 107.537ms
E/DropBoxTask: null InputStream
java.io.IOException: null InputStream
at wtd.a(:com.google.android.gms:182)
at wtd.b(:com.google.android.gms:124)
at wsi.a(:com.google.android.gms:88)
at com.google.android.gms.stats.service.DropBoxEntryAddedChimeraService.onHandleIntent(:com.google.android.gms:1176)
at bdz.handleMessage(:com.google.android.gms:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148) at android.os.HandlerThread.run(HandlerThread.java:61)
登录活动
public class SignInActivity extends BaseActivity implements View.OnClickListener {
private static final String TAG = "SignInActivity";
private DatabaseReference mDatabase;
private FirebaseAuth mAuth;
private EditText mEmailField;
private EditText mPasswordField;
private Button mSignInButton;
private Button mSignUpButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
mDatabase = FirebaseDatabase.getInstance().getReference();
mAuth = FirebaseAuth.getInstance();
// Views
mEmailField = (EditText) findViewById(R.id.field_email);
mPasswordField = (EditText) findViewById(R.id.field_password);
mSignInButton = (Button) findViewById(R.id.button_sign_in);
mSignUpButton = (Button) findViewById(R.id.button_sign_up);
// Click listeners
mSignInButton.setOnClickListener(this);
mSignUpButton.setOnClickListener(this);
}
@Override
public void onStart() {
super.onStart();
// Check auth on Activity start
if (mAuth.getCurrentUser() != null) {
onAuthSuccess(mAuth.getCurrentUser());
}
}
private void signIn() {
Log.d(TAG, "signIn");
if (!validateForm()) {
return;
}
showProgressDialog();
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signIn:onComplete:" + task.isSuccessful());
hideProgressDialog();
if (task.isSuccessful()) {
onAuthSuccess(task.getResult().getUser());
} else {
Toast.makeText(SignInActivity.this, "Sign In Failed",
Toast.LENGTH_SHORT).show();
}
}
});
}
private void signUp() {
Log.d(TAG, "signUp");
if (!validateForm()) {
return;
}
showProgressDialog();
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(
new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "createUser:onComplete:" + task.isSuccessful());
hideProgressDialog();
if (task.isSuccessful()) {
onAuthSuccess(task.getResult().getUser());
} else {
Toast.makeText(SignInActivity.this, "Sign Up Failed",
Toast.LENGTH_SHORT).show();
}
}
});
}
private void onAuthSuccess(FirebaseUser user) {
String username = usernameFromEmail(user.getEmail());
// Write new user
writeNewUser(user.getUid(), username, user.getEmail());
// Go to MainActivity
startActivity(new Intent(SignInActivity.this, MainActivity.class));
finish();
}
private String usernameFromEmail(String email) {
if (email.contains("@")) {
return email.split("@")[0];
} else {
return email;
}
}
private boolean validateForm() {
boolean result = true;
if (TextUtils.isEmpty(mEmailField.getText().toString())) {
mEmailField.setError("Required");
result = false;
} else {
mEmailField.setError(null);
}
if (TextUtils.isEmpty(mPasswordField.getText().toString())) {
mPasswordField.setError("Required");
result = false;
} else {
mPasswordField.setError(null);
}
return result;
}
// [START basic_write]
private void writeNewUser(String userId, String name, String email) {
User user = new User(name, email);
mDatabase.child("users").child(userId).setValue(user);
}
// [END basic_write]
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button_sign_in:
signIn();
break;
case R.id.button_sign_up:
signUp();
break;
}
}
}