簡體   English   中英

添加 Firebase 身份驗證后 Android 應用崩潰

[英]Android app crashing after adding Firebase authentication

我正在使用 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 助手窗口中,它顯示它已連接但每次我嘗試在我的真實設備上運行它時應用程序仍然崩潰? 請幫助不要評判我我剛剛開始自學。

嘗試在您的 gradle 文件中升級到'com.google.firebase:firebase-core:16.0.7''com.google.firebase:firebase-auth:16.1.0'

如果您注釋掉startActivity(startIntent); finish();應用程序還會崩潰嗎startActivity(startIntent); finish(); startActivity(startIntent); finish(); ?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM