GVKun编程网logo

没有创建 Firebase 应用“[DEFAULT]” - 在 Flutter 和 Firebase 中调用Firebase.initializeApp()

6

关于没有创建Firebase应用“[DEFAULT]”-在Flutter和Firebase中调用Firebase.initializeApp()的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多

关于没有创建 Firebase 应用“[DEFAULT]” - 在 Flutter 和 Firebase 中调用Firebase.initializeApp()的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于android – 使用FirebaseOptions的Init firebase、android-Firebase Analytics-firebase-core:9.0.0-FirebaseInstanceId:后台同步失败:INVALID_SENDER、com.google.firebase.auth.FirebaseAuthInvalidCredentialsException的实例源码、com.google.firebase.auth.FirebaseAuthInvalidUserException的实例源码等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

没有创建 Firebase 应用“[DEFAULT]” - 在 Flutter 和 Firebase 中调用Firebase.initializeApp()

没有创建 Firebase 应用“[DEFAULT]” - 在 Flutter 和 Firebase 中调用Firebase.initializeApp()

我正在构建一个 Flutter 应用程序并且我已经集成了 Firebase,但是当我单击一个按钮进行注册、登录或注销时,我不断收到这个错误。我见过其他人问过同样的问题,但似乎没有一个对我有用。我正在使用 Flutter 和Android Studio。我该如何解决这个问题?

这是我的代码的摘录

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.red,body: Center(
        child: Container(
          child: RaisedButton(
            onPressed: () {
              FirebaseAuth.instance.signOut().then((value) {
                Navigator.pushReplacement(
                    context,MaterialPageRoute(
                        builder: (context) =>
                            LoginScreen()));
              });
            },child: Text("Logout"),)
        )
      )
    );
  }
}

下面是抛出的异常

══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
The following FirebaseException was thrown while handling a gesture:
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()

When the exception was thrown,this was the stack:

#0      MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:118:5)
#1      Firebase.app (package:firebase_core/src/firebase.dart:52:41)
#2      FirebaseAuth.instance (package:firebase_auth/src/firebase_auth.dart:37:47)
#3      _HomeScreenState.build.<anonymous closure> (package:cosytok/screens/home.dart:20:28)
#4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992:19)
#5      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1098:38)
#6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24)
#7      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524:11)
#8      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5)
#9      BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:219:7)
#10     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:477:9)
#11     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:78:12)
#12     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:124:9)
#13     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
#14     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:122:18)
#15     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:108:7)
#16     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:220:19)
#17     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22)
#18     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158:7)
#19     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104:7)
#20     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88:7)
#24     _invoke1 (dart:ui/hooks.dart:267:10)
#25     _dispatchPointerDataPacket (dart:ui/hooks.dart:176:5)
(elided 3 frames from dart:async)

Handler: "onTap"
Recognizer:
  TapGestureRecognizer#f0104
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════════════════════════
The following FirebaseException was thrown while handling a gesture:
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()

android – 使用FirebaseOptions的Init firebase

android – 使用FirebaseOptions的Init firebase

我想在没有google-services.json的情况下使用FirebaSEOptions初始化Firebase,我正在关注此处的博客文章 https://firebase.googleblog.com/2017/03/take-control-of-your-firebase-init-on.html.

我删除了FirebaseInitProvider.

<provider
    android:name="com.google.firebase.provider.FirebaseInitProvider"
    android:authorities="${applicationId}.firebaseinitprovider"
    tools:node="remove"/>

我试图在Application子类中设置默认的FirebaseApp:

FirebaSEOptions options = new FirebaSEOptions.Builder()
                .setApplicationId("valid_app_id")
                .setGcmSenderId("valid_gcm_sender_id")
                .setApiKey("valid_api_key")
                .build();

FirebaseApp.initializeApp(getApplicationContext(),options);

似乎一切正常,但是当我想将一些事件记录到FirebaseAnalytics时,我收到此错误:缺少google_app_id. Firebase Analytics已停用.
我不知道是什么问题.

解决方法

如果您没有使用google-services.json文件,则JSON中存在的信息需要在某处才能读取插件/代码.您可以在此处执行的操作是使用具有以下属性的字符串资源手动创建XML文件:
google_app_id:

{YOUR_CLIENT}/client_info/mobilesdk_app_id
gcm_defaultSenderId:

project_info/project_number
default_web_client_id:

{YOUR_CLIENT}/oauth_client/client_id (client_type == 3)
ga_trackingId:

{YOUR_CLIENT}/services/analytics-service/analytics_property/tracking_id
firebase_database_url:

project_info/firebase_url
google_api_key:

{YOUR_CLIENT}/api_key/current_key
google_crash_reporting_api_key:

{YOUR_CLIENT}/api_key/current_key

看看here.确保添加google_app_id,没有它会导致错误发布.

如果您没有将“tools”命名空间添加到清单根标记中,则还必须添加它:

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="your.package"
    >

其余的实现方式与使用FirebaSEOptions和Firebase.InitializeApp()相同.

android-Firebase Analytics-firebase-core:9.0.0-FirebaseInstanceId:后台同步失败:INVALID_SENDER

android-Firebase Analytics-firebase-core:9.0.0-FirebaseInstanceId:后台同步失败:INVALID_SENDER

我遵循了以下页面上的说明:https://firebase.google.com/docs/android/setup#add_firebase_to_your_app

初始化过程运行良好,但我看到标题中提到的错误消息.

你知道该怎么办吗?

解决方法:

重新下载google-services.json后,消息消失了…
现在,我得到“ FirebaseInstanceId:主题同步成功”.

还是要谢谢你.也许这会帮助某人.

com.google.firebase.auth.FirebaseAuthInvalidCredentialsException的实例源码

com.google.firebase.auth.FirebaseAuthInvalidCredentialsException的实例源码

项目:Ae4Team    文件:ChangePhoneNumberActivity.java   
private void phoneNumberVerificationCB() {
    mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

        @Override
        public void onVerificationCompleted(PhoneAuthCredential credential) {
            Log.d(TAG,"onVerificationCompleted:" + credential);
            credent = credential;
        }

        @Override
        public void onVerificationFailed(FirebaseException e) {
            Log.w(TAG,"onVerificationFailed",e);

            if (e instanceof FirebaseAuthInvalidCredentialsException) {
                // Invalid request
                // ...
            } else if (e instanceof FirebasetooManyRequestsException) {
                // The SMS quota for the project has been exceeded
                // ...
            }
        }
    };
}
项目:SignUpPhone    文件:LoginActivity.java   
/**
 * Method to handle sign in;
 * @param v
 * @param phoneAuthCredential
 */
private void signIn(View v,PhoneAuthCredential phoneAuthCredential) {
    auth.signInWithCredential(phoneAuthCredential)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        redirectToMainActivity();
                    } else {
                        if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                            // The verification code entered was invalid
                            // [START_EXCLUDE silent]
                            verificationCodeEditext.setError("Invalid code.");
                            // [END_EXCLUDE]
                        }
                    }
                }
            });
}
项目:firebaseui-Android    文件:PhoneActivityTest.java   
@Test
@Config(shadows = {AuthHelperShadow.class})
public void testSubmitCode_badCodeShowsAlertDialog() {
    reset(AuthHelperShadow.getPhoneAuthProvider());
    when(AuthHelperShadow.getFirebaseAuth().signInWithCredential(any(AuthCredential.class)))
            .thenReturn(new AutoCompleteTask<AuthResult>(
                    null,true,new FirebaseAuthInvalidCredentialsException(
                            FirebaseAuthError.ERROR_INVALID_VERIFICATION_CODE.toString(),"any_msg")));
    testSendConfirmationCode();
    SpacedEditText mConfirmationCodeEditText = mActivity.findViewById(R.id.confirmation_code);
    Button mSubmitConfirmationButton = mActivity.findViewById(R.id.submit_confirmation_code);

    mConfirmationCodeEditText.setText("123456");
    mSubmitConfirmationButton.performClick();
    assertEquals(mActivity.getString(R.string.fui_incorrect_code_dialog_body),getAlertDialogMessage());

    //test bad code cleared on clicking OK in alert
    android.support.v7.app.AlertDialog a = mActivity.getAlertDialog();
    Button ok = a.findViewById(android.R.id.button1);
    ok.performClick();
    assertEquals("- - - - - -",mConfirmationCodeEditText.getText().toString());
}
项目:Raffler-Android    文件:RegisterPhoneActivity.java   
private void signInWithPhoneAuthCredential(final PhoneAuthCredential credential) {
    hud.show();
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this,new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    hud.dismiss();
                    if (task.isSuccessful()) {
                        // Sign in success,update UI with the signed-in user's information
                        Log.d(TAG,"signInWithCredential:success");

                        FirebaseUser user = task.getResult().getUser();
                        user.updatePhoneNumber(credential);

                        startActivity(new Intent(RegisterPhoneActivity.this,RegisterUserActivity.class));
                        RegisterPhoneActivity.this.finish();
                    } else {
                        // Sign in Failed,display a message and update the UI
                        Log.w(TAG,"signInWithCredential:failure",task.getException());
                        if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                            // The verification code entered was invalid
                            Toast.makeText(RegisterPhoneActivity.this,"The verification code entered was invalid",Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            });
}
项目:quickstart-android    文件:PhoneAuthActivity.java   
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this,new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success,"signInWithCredential:success");

                        FirebaseUser user = task.getResult().getUser();
                        // [START_EXCLUDE]
                        updateUI(STATE_SIGNIN_SUCCESS,user);
                        // [END_EXCLUDE]
                    } else {
                        // Sign in Failed,task.getException());
                        if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                            // The verification code entered was invalid
                            // [START_EXCLUDE silent]
                            mVerificationField.setError("Invalid code.");
                            // [END_EXCLUDE]
                        }
                        // [START_EXCLUDE silent]
                        // Update UI
                        updateUI(STATE_SIGNIN_Failed);
                        // [END_EXCLUDE]
                    }
                }
            });
}
项目:firebaseui-Android    文件:SignInDelegate.java   
/**
 * Begin sign in process with email and password from a SmartLock credential. On success,finish
 * with {@link Activity#RESULT_OK}. On failure,delete the credential from SmartLock (if
 * applicable) and then launch the auth method picker flow.
 */
private void signInWithEmailAndPassword(String email,String password) {
    final IdpResponse response =
            new IdpResponse.Builder(new User.Builder(EmailAuthProvider.PROVIDER_ID,email).build())
                    .build();

    getAuthHelper().getFirebaseAuth()
            .signInWithEmailAndPassword(email,password)
            .addOnSuccessListener(new OnSuccessListener<AuthResult>() {
                @Override
                public void onSuccess(AuthResult authResult) {
                    finish(Activity.RESULT_OK,response.toIntent());
                }
            })
            .addOnFailureListener(new TaskFailureLogger(
                    TAG,"Error signing in with email and password"))
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    if (e instanceof FirebaseAuthInvalidUserException
                            || e instanceof FirebaseAuthInvalidCredentialsException) {
                        // In this case the credential saved in SmartLock was not
                        // a valid credential,we should delete it from SmartLock
                        // before continuing.
                        deleteCredentialAndRedirect();
                    } else {
                        startAuthMethodChoice();
                    }
                }
            });
}
项目:Raffler-Android    文件:RegisterPhoneActivity.java   
private void verifyPhoneNumber(String phoneNumber){

        if (!isValid){
            Toast.makeText(this,"Invalid Phone number!",Toast.LENGTH_SHORT).show();
            return;
        }

        hud.show();
        mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

            @Override
            public void onVerificationCompleted(PhoneAuthCredential credential) {
                // This callback will be invoked in two situations:
                // 1 - Instant verification. In some cases the phone number can be instantly
                //     verified without needing to send or enter a verification code.
                // 2 - Auto-retrieval. On some devices Google Play services can automatically
                //     detect the incoming verification SMS and perform verification without
                //     user action.
                Log.d(TAG,"onVerificationCompleted:" + credential);

                hud.dismiss();

                signInWithPhoneAuthCredential(credential);
            }

            @Override
            public void onVerificationFailed(FirebaseException e) {
                // This callback is invoked in an invalid request for verification is made,// for instance if the the phone number format is not valid.
                Toast.makeText(RegisterPhoneActivity.this,e.getLocalizedMessage(),Toast.LENGTH_SHORT).show();

                if (e instanceof FirebaseAuthInvalidCredentialsException) {
                    // Invalid request
                    Toast.makeText(RegisterPhoneActivity.this,"Invalid mobile number",Toast.LENGTH_SHORT).show();
                } else if (e instanceof FirebasetooManyRequestsException) {
                    // The SMS quota for the project has been exceeded
                    Toast.makeText(RegisterPhoneActivity.this,"The SMS quota for the project has been exceeded",Toast.LENGTH_SHORT).show();
                }

                // Show a message and update the UI

                hud.dismiss();
            }

            @Override
            public void onCodeSent(String verificationId,PhoneAuthProvider.ForceResendingToken token) {
                // The SMS verification code has been sent to the provided phone number,we
                // Now need to ask the user to enter the code and then construct a credential
                // by combining the code with a verification ID.
                Log.d(TAG,"onCodeSent:" + verificationId);

                // Save verification ID and resending token so we can use them later
                phoneVerficationID = verificationId;
                resendToken = token;
                Toast.makeText(RegisterPhoneActivity.this,getString(R.string.register_verify_sent),Toast.LENGTH_SHORT).show();
                hud.dismiss();

                startResendTimer();
            }
        };

        PhoneAuthProvider.getInstance().verifyPhoneNumber(
                phoneNumber,60,TimeUnit.SECONDS,this,mCallbacks);

    }
项目:IIITconnect    文件:FirebaseUtils.java   
public static void Authenticate(final Context mContext,final String id,final String password) {

        //converting the roll number to uppercase
        String capsRollNumber = id.toupperCase();

        if (!Patterns.EMAIL_ADDRESS.matcher(capsRollNumber).matches()) {
            // username
            DatabaseReference db = FirebaseDatabase.getInstance().getReference();
            Query user_query = db.child("users").orderByChild("rollNumber").equalTo(capsRollNumber);
            user_query.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    // dataSnapshot returns list of users
                    if (dataSnapshot.getChildrenCount() > 0) {
                        // get the first element
                        UserInfo userInfo = dataSnapshot.getChildren().iterator().next().getValue(UserInfo.class);
                        if (userInfo != null)
                            Authenticate(mContext,userInfo.email,password);
                    } else {
                        Toast.makeText(mContext,"Roll Number does not exist",Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                    Toast.makeText(mContext,"Oops,something went wrong!",Toast.LENGTH_SHORT).show();
                }
            });
            return;
        }

        final FirebaseAuth auth = FirebaseAuth.getInstance();
        auth.signInWithEmailAndPassword(id,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                    // Sign in success,update UI with the signed-in user's information
                    sUser = auth.getCurrentUser();
                    mContext.startActivity(new Intent(mContext,NavigationDrawerActivity.class));
                } else {
                    // If sign in fails,display a message to the user.
                    if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                        Toast.makeText(mContext,"Invalid Password! Try Again",Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(mContext,"Email does not exist",Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
    }
项目:SignUpPhone    文件:LoginActivity.java   
/**
 * Method to handle sign up process
 *
 * @param v
 */
private void signUp(final View v) {
    if (phoneNoEditext.length() == 0) { // if phone no field empty
        Snackbar.make(v,R.string.insertphoneno,Snackbar.LENGTH_LONG)
                .show();
        return;
    }


    String phoneNumber = phoneNoEditext.getText().toString();

    // copy code from google
    // https://firebase.google.com/docs/auth/android/phone-auth
    // code to verify phone number.
    PhoneAuthProvider.getInstance().verifyPhoneNumber(
            phoneNumber,// Phone number to verify
            60,// Timeout duration
            TimeUnit.SECONDS,// Unit of timeout
            this,// Activity (for callback binding)
            new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
                @Override
                public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
                    signIn(v,phoneAuthCredential);
                }

                @Override
                public void onVerificationFailed(FirebaseException e) {
                    if (e instanceof FirebaseAuthInvalidCredentialsException) {
                        // Invalid request
                        // [START_EXCLUDE]
                        phoneNoEditext.setError("Invalid phone number.");
                        // [END_EXCLUDE]
                    } else if (e instanceof FirebasetooManyRequestsException) {
                        // The SMS quota for the project has been exceeded
                        // [START_EXCLUDE]
                        Snackbar.make(findViewById(android.R.id.content),"Quota exceeded.",Snackbar.LENGTH_SHORT).show();
                        // [END_EXCLUDE]
                    }
                }

                @Override
                public void onCodeSent(String s,PhoneAuthProvider.ForceResendingToken forceResendingToken) {
                    super.onCodeSent(s,forceResendingToken);

                    verificationId = s;
                    showVerificationLayout();
                }


            });
}

com.google.firebase.auth.FirebaseAuthInvalidUserException的实例源码

com.google.firebase.auth.FirebaseAuthInvalidUserException的实例源码

项目:firebaseui-Android    文件:RecoverPasswordActivity.java   
private void next(final String email) {
    getAuthHelper().getFirebaseAuth()
            .sendPasswordResetEmail(email)
            .addOnFailureListener(
                    new TaskFailureLogger(TAG,"Error sending password reset email"))
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    getDialogHolder().dismissDialog();
                    RecoveryEmailSentDialog.show(
                            email,getSupportFragmentManager());
                }
            })
            .addOnFailureListener(this,new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    getDialogHolder().dismissDialog();

                    if (e instanceof FirebaseAuthInvalidUserException) {
                        // No FirebaseUser exists with this email address,show error.
                        mEmailEditText.setError(getString(R.string.fui_error_email_does_not_exist));
                    }
                }
            });
}
项目:firebaseui-Android    文件:SignInDelegate.java   
/**
 * Begin sign in process with email and password from a SmartLock credential. On success,finish
 * with {@link Activity#RESULT_OK}. On failure,delete the credential from SmartLock (if
 * applicable) and then launch the auth method picker flow.
 */
private void signInWithEmailAndPassword(String email,String password) {
    final IdpResponse response =
            new IdpResponse.Builder(new User.Builder(EmailAuthProvider.PROVIDER_ID,email).build())
                    .build();

    getAuthHelper().getFirebaseAuth()
            .signInWithEmailAndPassword(email,password)
            .addOnSuccessListener(new OnSuccessListener<AuthResult>() {
                @Override
                public void onSuccess(AuthResult authResult) {
                    finish(Activity.RESULT_OK,response.toIntent());
                }
            })
            .addOnFailureListener(new TaskFailureLogger(
                    TAG,"Error signing in with email and password"))
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    if (e instanceof FirebaseAuthInvalidUserException
                            || e instanceof FirebaseAuthInvalidCredentialsException) {
                        // In this case the credential saved in SmartLock was not
                        // a valid credential,we should delete it from SmartLock
                        // before continuing.
                        deleteCredentialAndRedirect();
                    } else {
                        startAuthMethodChoice();
                    }
                }
            });
}

关于没有创建 Firebase 应用“[DEFAULT]” - 在 Flutter 和 Firebase 中调用Firebase.initializeApp()的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于android – 使用FirebaseOptions的Init firebase、android-Firebase Analytics-firebase-core:9.0.0-FirebaseInstanceId:后台同步失败:INVALID_SENDER、com.google.firebase.auth.FirebaseAuthInvalidCredentialsException的实例源码、com.google.firebase.auth.FirebaseAuthInvalidUserException的实例源码的相关信息,请在本站寻找。

本文标签: