我正在使用Firebase开发一个Android应用程序,但是该应用程序在没有Firebase的情况下也可以正常工作,最糟糕的是android studio没有显示错误,但是在添加Firebase身份验证后该应用程序崩溃了。有什么问题吗?任何帮助表示赞赏。
我尝试更改firebase的版本,尝试更改Gradle文件,并在firebase中创建了其他项目,以查看是否有任何改变
package com.example.manual;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.EditText;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class MainActivity extends AppCompatActivity {
EditText e1,e2;
FirebaseAuth mAuth ;
FirebaseUser currentUser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//e1 = (EditText) findViewById(R.id.edit)
mAuth = FirebaseAuth.getInstance();
currentUser = mAuth.getCurrentUser();
}
@Override
public void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
if(currentUser == null){
Intent startIntent = new
Intent(MainActivity.this,RegisterActivity.class);
startActivity(startIntent);
finish();
}
}
}
Gradele file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.manual"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-
optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
核心:3.0.2' }
apply plugin: 'com.google.gms.google-services'
Project manual file
// Top-level build file where you can add configuration options common to
all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
在Firebase助手窗口中,表示已连接,但仍然 每次尝试在真实设备上运行应用程序时,应用程序崩溃?请帮忙 不要判断我,我只是开始自学。
答案 0 :(得分:0)
尝试在gradle文件中升级到'com.google.firebase:firebase-core:16.0.7'
和'com.google.firebase:firebase-auth:16.1.0'
。
如果您注释掉startActivity(startIntent);
finish();
,应用程序还会崩溃吗?