firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
829 stars 429 forks source link

Firebase Dynamic Links Fail To Generate On Real Device #308

Closed xtrecoolx closed 5 years ago

xtrecoolx commented 5 years ago

Please fill in the following fields:

Unity editor version: Unity 2018.3.0f2 Firebase Unity SDK version: 5.4.3 Additional SDKs you are using (Facebook, AdMob, etc.): Admob and Facebook Platform you are using the Unity editor on (Mac, Windows, or Linux): Mac Platform you are targeting (iOS, Android, and/or desktop): Android

Please describe the issue here:

(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)

I have created a simple long and short dynamic link generator to my application by following the examples in the quick start. In the Unity editor, I have seen the message that short link generation is not supported but the long link is generated. So I have decided to test it on a real device. However, the device logs show something weird:

E/Unity (31595): ApplicationException: internal::IsInitialized() E/Unity (31595): at Firebase.DynamicLinks.FirebaseDynamicLinks.GetLongLinkInternal (Firebase.DynamicLinks.DynamicLinkComponentsInternal components) [0x00021] in :0 E/Unity (31595): at Firebase.DynamicLinks.DynamicLinkComponents.get_LongDynamicLink () [0x00006] in :0 E/Unity (31595): at ReferralsPopup.CreateAndDisplayLongLink () [0x00006] in :0 E/Unity (31595): at ReferralsPopup.Start () [0x00028] in :0

This kind of sounds like another instance of Firebase is trying to be called ?? If so, why is this error not produced in the editor ? I can't seem to get this running on a real device. Please help.

Please answer the following, if applicable:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? I don't really have the time to test it.

a-maurice commented 5 years ago

Based on that error log, it looks like Firebase is not being initialized, but that should happen automatically via a static constructor on FirebaseDynamicLinks. Can you share the code snippet you used to get this problem? Also, I assume there were no errors in the logs before that part that you shared?

xtrecoolx commented 5 years ago

Since Firebase is initialized at the startup scene, I am not trying to initialize it again. The code is from a different scene as follows and I call CreateAndDisplayUnguessableShortLinkAsync() in void Start(). It works in Editor but not on device:

`Firebase.DynamicLinks.DynamicLinkComponents CreateDynamicLinkComponents() {

        var json = JWT.JsonWebToken.Decode(PlayerPrefs.GetString("uuid"));
        DataModel.JWTObject jwtObject = JsonConvert.DeserializeObject<DataModel.JWTObject>(json);
        var user_id = jwtObject.user_id;

                return new Firebase.DynamicLinks.DynamicLinkComponents(
                    // The base Link.
                    new System.Uri("https://www.somedomain.com?inviter="+user_id),
                    // The dynamic link domain.
                    ConfigurationController.dynamicLinkdomain) {
                    GoogleAnalyticsParameters = new Firebase.DynamicLinks.GoogleAnalyticsParameters() {
                    Source = "inapp",
                    Medium = "inapp",
                    Campaign = "local",
                    Term = "referral",
                    Content = "referral"
                    },
                    IOSParameters = new Firebase.DynamicLinks.IOSParameters(ConfigurationController.appIdIos) {
                    FallbackUrl = new System.Uri("https://www.somedomain.com"),
                    CustomScheme = "mycustomscheme",
                    MinimumVersion = "1.2.3",
                    IPadBundleId = ConfigurationController.appIdIos,
                    IPadFallbackUrl = new System.Uri("https://www.somedomain.com")
                    },
                    AndroidParameters = new Firebase.DynamicLinks.AndroidParameters(ConfigurationController.appIdAndroid) {
                    FallbackUrl = new System.Uri("https://www.somedomain.com"),
                    MinimumVersion = 17
                    },
                };
}

    public Uri CreateAndDisplayLongLink() {
        var longLink = CreateDynamicLinkComponents().LongDynamicLink;
        Debug.Log(String.Format("Long dynamic link {0}", longLink));
        return longLink;
    }

    public Task<Firebase.DynamicLinks.ShortDynamicLink> CreateAndDisplayShortLinkAsync() {
        return CreateAndDisplayShortLinkAsync(new Firebase.DynamicLinks.DynamicLinkOptions());
    }

    public Task<Firebase.DynamicLinks.ShortDynamicLink> CreateAndDisplayUnguessableShortLinkAsync() {
        return CreateAndDisplayShortLinkAsync(new Firebase.DynamicLinks.DynamicLinkOptions {
        PathLength = Firebase.DynamicLinks.DynamicLinkPathLength.Unguessable
    });
    }

    private Task<Firebase.DynamicLinks.ShortDynamicLink> CreateAndDisplayShortLinkAsync(Firebase.DynamicLinks.DynamicLinkOptions options) {
    if (ConfigurationController.dynamicLinkdomain == kInvalidDynamicLinksDomain) {
        Debug.Log("Dynamic link domain error");
        var source = new TaskCompletionSource<Firebase.DynamicLinks.ShortDynamicLink>();
        source.TrySetException(new Exception("Dynamic link domain error"));
        return source.Task;
    }

    var components = CreateDynamicLinkComponents();
    return Firebase.DynamicLinks.DynamicLinks.GetShortLinkAsync(components, options)
        .ContinueWith<Firebase.DynamicLinks.ShortDynamicLink>((task) => {
        if (task.IsCanceled) {
            Debug.Log("Short link creation canceled");
        } else if (task.IsFaulted) {
            Debug.Log(String.Format("Short link creation failed {0}", task.Exception.ToString()));
        } else {
            Firebase.DynamicLinks.ShortDynamicLink link = task.Result;
            Debug.Log(String.Format("Generated short link {0}", link.Url));
            this.shortLink = link.Url.AbsoluteUri;
            var warnings = new System.Collections.Generic.List<string>(link.Warnings);
            if (warnings.Count > 0) {
            Debug.Log("Warnings:");
            foreach (var warning in warnings) {
                Debug.Log("  " + warning);
            }
            }
        }
        return task.Result;
        });
    }`
xtrecoolx commented 5 years ago

I would like to also add that listening to dynamic links do not seem to work either. On my startup scene, I have put the following code and it never captures any dynamic links:

Firebase.DynamicLinks.DynamicLinks.DynamicLinkReceived += OnDynamicLink;

` void OnDynamicLink(object sender, EventArgs args) {

            Debug.Log("There is a dynamic link");

            var dynamicLinkEventArgs = args as Firebase.DynamicLinks.ReceivedDynamicLinkEventArgs;
            Debug.Log(String.Format("Received dynamic link {0}",dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString));

    }`

The documentation is really poor on DynamicLinks and people are struggling to figure out how it works in Stackoverflow. Please guide us.

a-maurice commented 5 years ago

Thanks for the additional information. I haven't been able to reproduce the problem locally with our quickstarts, but they do not use scenes as you are describing, so possible there is an odd interaction happening with that, which we will investigate further.

xtrecoolx commented 5 years ago

Well for me the receiving part is more important and that sits on the first scene. I am already creating the short link via API so I would be really happy if you can guide me why the OnDynamicLink won't fire.

xtrecoolx commented 5 years ago

@a-maurice i am out of ideas

a-maurice commented 5 years ago

Looking through everything you've sent, and trying it out on my end, I'm still not sure why you are having a problem receiving links. Did you set the SHA certificate on your project? You might need to file a support ticket with https://firebase.google.com/support/troubleshooter/, which will allow a more precise look into the problems you are facing.

xtrecoolx commented 5 years ago

Yes I did set the SHA from the values provide by Google Play Console. The support is very slow. Do we need to have an intent-filter for androidmanifest.xml for dynamic links to work ? I see this in documentation for Android but in Unity it does not seem to be generated.

xtrecoolx commented 5 years ago

@a-maurice This is really upsetting. Nobody is answering on the other thread either. I am paying for Firebase and your support does not answer either. I am not trying to achieve something extra ordinary here.

a-maurice commented 5 years ago

You should not have to set up the intent-filter, as we handle that part automatically as part of the Unity SDK. The only steps you should have to do are those listed on: https://firebase.google.com/docs/dynamic-links/unity/receive

Using the correct SHA key is important, so make sure you are using the correct one. You can get instructions on how to get the debug one that your machine is using here: https://developers.google.com/android/guides/client-auth If you are building for release, that also has instructions on getting it from the keystore used to sign.

That is annoying that the support ticket team is not reaching out to you about the problem you are seeing. I will reach out to that group to see if there is a reason for that.

katowulf commented 5 years ago

@xtrecoolx can you email me the support case id (found in the auto reply subject)? I'll be happy to have a look and see what's going on: katowulf at google

stewartmiles commented 5 years ago

@xtrecoolx I'll assume your issue is being solved via our support channel. If we learn anything that we can roll into documentation or editor plugin improvements we'll post here.

stickpool commented 5 years ago

@xtrecoolx Did you manage to solve the issue? We're facing this exact problem.

alexames commented 5 years ago

@stickpool, if you're having a similar issue, can you open a new issue and fill out the requested information on your versions and platform? Also, can you try running the quickstart project to see if the issue reproduces there?