TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
214 stars 50 forks source link

Exception:Default FirebaseApp is not initialized in this process #4

Closed sattasundar closed 3 years ago

sattasundar commented 3 years ago

Thanks Budyy that build error is resolved.

Now I got a Challenge;

**MainActivity

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(savedInstanceState);

        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        FirebaseApp.InitializeApp(this);
        CrossFirebase.Initialize(this, savedInstanceState, CreateCrossFirebaseSettings());
        HandleIntent(Intent);
        LoadApplication(new App());
    }

    private static CrossFirebaseSettings CreateCrossFirebaseSettings()
    {
        return new CrossFirebaseSettings(
            isAnalyticsEnabled:true,
            isAuthEnabled:true,
            isCloudMessagingEnabled:true,
            isDynamicLinksEnabled: true,
            isFirestoreEnabled: true,
            isFunctionsEnabled: true,
            isRemoteConfigEnabled: true,
            isStorageEnabled: true
            //facebookId: "", //Facebook client id
            //facebookAppName: "", // App Name over facebook
            //googleRequestIdToken: ""
            );
    }

    private static void HandleIntent(Intent intent)
    {
        FirebaseCloudMessagingImplementation.OnNewIntent(intent);
        FirebaseDynamicLinksImplementation.HandleDynamicLinkAsync(intent);
    }

    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
    {
        Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

        base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);
        FirebaseAuthImplementation.HandleActivityResultAsync(requestCode, resultCode, data);
    }

    protected override void OnNewIntent(Intent intent)
    {
        base.OnNewIntent(intent);
        HandleIntent(intent);
    }
}

**MainPage.xaml.cs

public partial class MainPage : ContentPage { private readonly Lazy _firebaseAuth; private IFirebaseAuth _fireAuth; public MainPage() { InitializeComponent(); _firebaseAuth = new Lazy(CreateFirebaseAuth); } private static IFirebaseAuth CreateFirebaseAuth() => CrossFirebaseAuth.Current; async void ClickMe(System.Object sender, System.EventArgs e) { try { _fireAuth = _firebaseAuth.Value; await _fireAuth.VerifyPhoneNumberAsync(phoneEntry.Text); } catch(Exception ex) { await DisplayAlert("Error", ex.Message, "Okay"); } } }

Is anything I am missing? Because I getting the exception alert which is in screenshot;
Screenshot 2021-01-19 at 5 48 53 PM
TobiasBuchholz commented 3 years ago

Try to add one package explicitly in the .csproj file of your android project, e.g:

<PackageReference Include="Xamarin.Firebase.Analytics" Version="118.0.0" />

I don't know why this is necessary but it seems to help. I will update the README accordingly.

sattasundar commented 3 years ago

@TobiasBuchholz No still same issue is coming.

Default FirebaseApp is not initialized in this process org.satsang.diksha. Make sure to call FirebaseApp.initializeApp(Context) first.

TobiasBuchholz commented 3 years ago

Have you cleaned the solution (also delete bin/ and obj/ folders) and restored packages? Restart Visual Studio? The usual stuff.. ¯_(ツ)_/¯

Which PackageReference did you add? From my experience either Analytics, DynamicLinks or RemoteConfig seem to work.

sattasundar commented 3 years ago

@TobiasBuchholz Have added the package what you have mentioned in previous comment.

After clearing all bin/obj and temp file now I am getting this;

Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed) [System] Ignoring header X-Firebase-Locale because its value was null. [EGL_emulation] eglMakeCurrent: 0xebf7f880: ver 3 0 (tinfo 0xb70dade0) [FirebaseAuth] [GetAuthDomainTask] Error getting project config. Failed with { [FirebaseAuth] "error": { [FirebaseAuth] "code": 400, [FirebaseAuth] "message": "INVALID_CERT_HASH", [FirebaseAuth] "errors": [ [FirebaseAuth] { [FirebaseAuth] "message": "INVALID_CERT_HASH", [FirebaseAuth] "domain": "global", [FirebaseAuth] "reason": "invalid" [FirebaseAuth] } [FirebaseAuth] ] [FirebaseAuth] } [FirebaseAuth] } [FirebaseAuth] 400 [zzf] Failed to get reCAPTCHA token - calling backend without app verification [EGL_emulation] eglMakeCurrent: 0xebf7f880: ver 3 0 (tinfo 0xb70dade0) [System] Ignoring header X-Firebase-Locale because its value was null. [System] A resource failed to call end. [System] A resource failed to call end. [FirebaseAuth] [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17042 Invalid format.

TobiasBuchholz commented 3 years ago

Seems like there is something wrong with your firebase config. Did you follow the steps from the basic and auth setup?

The 'Default FirebaseApp is not initialized' issue is solved, correct? If that's the case please close this issue and create a new one if necessary.

sattasundar commented 3 years ago

@TobiasBuchholz Sorry! Actually It's my fault and was missing the Country code.

So including country code it is working e.g. for India; +91XXXXXXXXXX

thanks a lot @TobiasBuchholz for the active reply and support.

will connect in near future if any challenges or issue appeared.

sattasundar commented 3 years ago

@TobiasBuchholz Countered same issue today; Default FirebaseApp is not initialized

Screenshot_1614752724

Can find Sample Code here

TobiasBuchholz commented 3 years ago

The package name in your google-services.json (com.xamarin.auth) doesn't match with the one in your AndroidManifest.xml (org.satsang.diksha). You either have to change it back in the AndroidManifest.xml or if you want to use the other package name you'll have to create a new app in the firebase console for that and replace the google-services.json file.

sattasundar commented 3 years ago

Thanks @TobiasBuchholz . It's my bad. Now it's working.

Kapusch commented 2 years ago

I encountered the same issue and have been able to solve it by following this procedure :

  1. Referencing the package Xamarin.Firebase.Analytics directly in the Android project,
  2. Cleaning the projects (obj & bin folders to be deleted)
  3. Restoring NuGet packages