Android视频通话崩溃

问题描述 投票:0回答:1

[我正在使用Java语言在android中构建视频通话应用程序,其中依赖项出错。在Java代码,xml文件和所有依赖项下面都编写了。我不知道为什么会出错。我已经定义了全部。用谷歌搜索很多

MainActivity.java

package com.example.dekho;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.google.firebase.FirebaseApp;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.PhoneAuthProvider;
import com.hbb20.CountryCodePicker;
import java.util.concurrent.TimeUnit;





import java.util.concurrent.TimeUnit;

public class MainActivity extends AppCompatActivity {

    private CountryCodePicker ccp;
    private EditText phoneText;
    private EditText codeText;
    private Button continueAndNextBtn;
    private String checker="",phoneNumber="";
    private RelativeLayout relativeLayout;
    private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;
    private FirebaseAuth mAuth;
    private String mVerificationId;
    private PhoneAuthProvider.ForceResendingToken mSendToken;
    private ProgressDialog loadingBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ccp=findViewById(R.id.ccp);
        phoneText=findViewById(R.id.phoneText);
        codeText=findViewById(R.id.codeText);
        continueAndNextBtn=findViewById(R.id.continueNextButton);
        relativeLayout=findViewById(R.id.phoneAuth);
        FirebaseApp.initializeApp(this);
        continueAndNextBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PhoneAuthProvider.getInstance().verifyPhoneNumber(
                        phoneNumber,        // Phone number to verify
                        60,                 // Timeout duration
                        TimeUnit.SECONDS,   // Unit of timeout
                        MainActivity.this,               // Uses the <ActivityName>.this instead of just "this" Activity (for callback binding)
                        mCallbacks);        // OnVerificationStateChangedCallbacks


            }
        });






















    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/register"
    tools:context=".MainActivity">


    <TextView
        android:id="@+id/textview1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="260dp">
    </TextView>


    <RelativeLayout
        android:id="@+id/phoneAuth"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textview1"
        android:layout_marginLeft="25dp"
        android:layout_marginRight="25dp"
        android:padding="8dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Phone Number:"
                android:textStyle="bold"
                android:textColor="@android:color/white"
                android:textSize="18sp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical">

                <com.hbb20.CountryCodePicker
                    android:id="@+id/ccp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@android:color/white"
                    app:ccp_defaultNameCode="IN" />

                <EditText
                    android:id="@+id/phoneText"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:textColor="@android:color/white"
                    android:textColorHint="@android:color/darker_gray"
                    android:inputType="phone"
                    android:singleLine="true"
                    android:backgroundTint="@android:color/white"/>
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>



    <EditText
        android:id="@+id/codeText"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_margin="25dp"
        android:hint="Write you code here..."
        android:textColor="@android:color/white"
        android:textColorHint="@android:color/white"
        android:inputType="phone"
        android:singleLine="true"
        android:layout_below="@+id/phoneAuth"
        android:drawableLeft="@drawable/password"
        android:drawableTint="@android:color/white"
        android:backgroundTint="@android:color/white"
        android:visibility="gone"/>

    <Button
        android:id="@+id/continueNextButton"
        android:layout_width="120dp"
        android:layout_height="40dp"
        android:layout_below="@+id/codeText"
        android:layout_centerHorizontal="true"
        android:text="Continue"
        android:textAllCaps="false"
        android:layout_marginTop="6dp"
        android:textSize="15dp"
        android:background="@color/colorPrimary"
        android:textColor="@android:color/white"/>


</RelativeLayout>

项目级依赖项

// 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.6.2'
        classpath 'com.google.gms:google-services:4.2.0'



        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用程序级别依赖项

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.dekho"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.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.google.firebase:firebase-core:17.3.0'
    implementation 'com.google.firebase:firebase-database:19.2.1'
    implementation 'com.google.firebase:firebase-storage:19.1.1'
    implementation "com.firebaseui:firebase-ui-database:0.4.0"
    implementation "com.firebaseui:firebase-ui-auth:0.4.0"
    implementation 'com.hbb20:ccp:2.1.9'
    implementation  'pub.devrel:easypermissions:0.4.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-core:11.4.0'
    implementation 'com.google.firebase:firebase-messaging:11.4.0'
    implementation 'com.google.firebase:firebase-auth:11.4.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'





}

错误日志

    --------- beginning of crash
2020-04-17 13:41:41.741 9995-9995/com.example.dekho E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.dekho, PID: 9995
    java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.dekho. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@19.3.0:184)
        at com.google.firebase.auth.PhoneAuthProvider.getInstance(Unknown Source:2)
        at com.example.dekho.MainActivity$1.onClick(MainActivity.java:51)
        at android.view.View.performClick(View.java:6647)
        at android.view.View.performClickInternal(View.java:6620)
        at android.view.View.access$3100(View.java:791)
        at android.view.View$PerformClick.run(View.java:26346)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7081)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:536)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:928)
2020-04-17 13:41:41.782 9995-9995/com.example.dekho I/Process: Sending signal. PID: 9995 SIG: 9
android
1个回答
0
投票
在应用Gradle的末尾添加应用插件:“ com.google.gms.google-services”:
© www.soinside.com 2019 - 2024. All rights reserved.