firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
234 stars 38 forks source link

[Bug] Unable to open app from Dynamic Link in android 13 devices #725

Closed thesanketkale closed 1 year ago

thesanketkale commented 1 year ago

Steps to reproduce:

  1. Get an Android device with Android 13 or Samsung Tablet S8+
  2. Install this app
  3. After installing, click on this link from the mobile device: https://link.vuexr.com/sl/vxrgBbwsXCsYM8nEA

What's the issue repro rate? (eg 100%, 1/5 etc) 100%

What happened? How can we make the problem occur? Click on the link from a mobile phone after installing the app on an Android 13 device and you shall see the app does not open. It used to work on earlier android versions on our testing devices, but since updating to android 13 the issue started.

paulinon commented 1 year ago

Hi @thesanketkale,

Thanks for bringing this to our attention. Could you try if updating the Firebase SDK to its latest version makes any difference?

thesanketkale commented 1 year ago

Hi @thesanketkale,

Thanks for bringing this to our attention. Could you try if updating the Firebase SDK to its latest version makes any difference?

Hi @paulinon, I tried it and didn't see any difference, the behavior is the same as with Firebase version 9.6.0. It still does not open the app on clicking the dynamic link with Firebase version 11.0.0. However, similar to the older Firebase version, it does open the link in the browser and then shows the white loader for some seconds, but after that does not open the app. It also holds on to the intent data somehow, and when I manually open the app by clicking on the app icon, it opens the content which it was supposed to open on receiving the dynamic link.

Just to reassert, this is only happening with Android devices having OS version 13 or higher. It is working as expected on older versions prior to this as well as on iOS devices.

paulinon commented 1 year ago

Thanks for the update, @thesanketkale. Based on the manifest file you provided, you seem to have an intent filter which takes your dynamic link details (android:host="vuexr.page.link"). Could you try removing this intent filter and see if it makes a difference?

thesanketkale commented 1 year ago

Thanks for the update, @thesanketkale. Based on the manifest file you provided, you seem to have an intent filter which takes your dynamic link details (android:host="vuexr.page.link"). Could you try removing this intent filter and see if it makes a difference?

I updated the manifest but still the same result. It does not open the app on clicking the dynamic link. What else can I try to fix this?

paulinon commented 1 year ago

Hi @thesanketkale,

It would be worth trying to have the hosts of your remaining intent filters start with www.. Could you try it out and see if it makes any difference?

thesanketkale commented 1 year ago

Hi @thesanketkale,

It would be worth trying to have the hosts of your remaining intent filters start with www.. Could you try it out and see if it makes any difference?

Nope, it's the same behavior after adding www to the host. I don't think it's in the manifest, it works fine on devices with Android 12 or below. Is there any change in how Firebase Dynamic links are managed on Android 13?

Also, am I the only one who has raised this issue?

Please tell me if there is any workaround for this. This issue is hampering the app flow on Android devices and dynamic links are quite a major and important entry point for our app users.

paulinon commented 1 year ago

Thanks for letting me know, @thesanketkale. Could you provide a minimal, reproducible example of your implementation? This could be used as a baseline for troubleshooting so that we can identify what's causing this behavior. You may upload this to a private GitHub repository with all personally identifiable information scrubbed and add me as a collaborator.

thesanketkale commented 1 year ago

Thanks for letting me know, @thesanketkale. Could you provide a minimal, reproducible example of your implementation? This could be used as a baseline for troubleshooting so that we can identify what's causing this behavior. You may upload this to a private GitHub repository with all personally identifiable information scrubbed and add me as a collaborator.

Hi @paulinon, as requested, I have created a minimalist reproducible example project with our project settings and Firebase plugin files and added you as a contributor to help debug this issue.

The example project is a simple Unity project that prints the URL on the screen after clicking on the dynamic link. Now, due to the said issue, you will not be able to open the app directly on clicking on a dynamic link shared in the OG post from a device with Android 13 or later, so after clicking on the dynamic link, open the app manually and you will see that the URL from the dynamic link gets displayed on the screen.

Kindly check it and let me know in case of any queries.

P.S. - There was this com.google.firebase.app-11.0.0.tgz file in the Packages folder which I was not able to commit due to file size limitations. You can get the file from here: https://dl.google.com/games/registry/unity/com.google.firebase.app/com.google.firebase.app-11.0.0.tgz and place it in "Packages\firebase_unity_sdk_11.0.0" folder.

paulinon commented 1 year ago

Thanks for providing the sample project, @thesanketkale. I was able to observe the difference when using both an Android 12 and Android 13 device. That said, I've relayed my observations to the team, and I'll let you know of any updates via this thread. I'll be marking this as a bug for now.

thesanketkale commented 1 year ago

Thanks for the update @paulinon. This is a blocker for our app in production, so request you to take this up with appropriate priority. Also, kindly let me know if you are able to find any workaround for this. Thanks.

thesanketkale commented 1 year ago

Any update on this? Just to reiterate, kindly let me know if there is any workaround for this. Dynamic links are quite an important part of the sharing feature in our app and it is breaking the user journey for new as well as existing users. Could this be arising from any backend misconfiguration in the console?

unnanego commented 1 year ago

I can confirm - same problem, not opening the app, goes straight to the fallback link with both version 9+ and 11.0.0

thesanketkale commented 1 year ago

I can observe the same behavior when built with the current latest public version of Unity 2022.3.0f1. @paulinon, Do we have any update on this?

a-maurice commented 1 year ago

Hi all,

So the issue is because of new restrictions on intent filters. For more information see here: https://developer.android.com/about/versions/13/behavior-changes-all#intents

The fix seems to be that additional logic needs to be added to the AndroidManifest.xml file. You might have one in Assets/Plugins/Android, otherwise you should be able to just make one there. The lines to add are covered here: https://firebase.google.com/docs/dynamic-links/android/receive#add-an-intent-filter-for-deep-links

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data
        android:host="example.com"
        android:scheme="https"/>
</intent-filter>

I will try to see if we can generate that as part of the SDK (though that might be hard, as we would need the information to replace "example.com" from that example shown), but in the meantime you should be able to add those lines yourselves, and that should resolve the issue for you.

thesanketkale commented 1 year ago

Hi @a-maurice, thanks for the response.

Could you please share a sample AndroidManifest.xml with this suggested change? I have tried different ways to add this intent filter but I am unable to get it to work.

a-maurice commented 1 year ago

What you have generally seems correct to me. One possible change would be using android:pathPrefix="/sl". Based on

      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data
            android:host="link.vuexr.com"
            android:scheme="https"
            android:pathPrefix="/sl"
        />
      </intent-filter>
thesanketkale commented 1 year ago

Hi @a-maurice, I am still not able to get it working on my Android 13 device. I have created a minimalist reproducible example project with our project settings and Firebase plugin files and added you as a contributor.

The example project is a simple Unity project that prints the URL on the screen after clicking on the dynamic link. Now, due to the said issue, you will not be able to open the app directly by clicking on a dynamic link shared in the OG post from a device with Android 13 or later.

Kindly check it and let me know how can I solve this issue. This issue is breaking our link-sharing feature in the Android app in production and I request you to look into the project and tell me what could be wrong and how can I fix it.

P.S. - There was this com.google.firebase.app-11.0.0.tgz file in the Packages folder which I was not able to commit due to file size limitations. You can get the file from here: https://dl.google.com/games/registry/unity/com.google.firebase.app/com.google.firebase.app-11.0.0.tgz and place it in "Packages\firebase_unity_sdk_11.0.0" folder.

thesanketkale commented 1 year ago

Hi @a-maurice, did you get a chance to look into the reproducible project? Could this be arising due to some misconfiguration in the Firebase console? It's been over a month since I raised this and I am desperate here. I was hoping you could help me identify the root cause soon.

a-maurice commented 1 year ago

Sorry for the delayed response, I've been trying to figure out what the problem might be, but haven't been able to reliably reproduce it. This doesn't seem to be reproducible on Android emulators (the links always work), so I've been trying to get a real device to test with.

In the meantime, if you think it is a problem with a misconfiguration in the Firebase console you could try making a support ticket via https://firebase.google.com/support. They'll be able to access your Firebase project that way, and be able to validate that everything is correct.

thesanketkale commented 1 year ago

Hi @a-maurice, I raised a support ticket and I am waiting for their response.

Were you able to reproduce the issue on a real device? Were you able to figure out the root cause? Is it just me facing this issue or have you got any other bug reports related to this?

Please give me some solution or a workaround, I am getting more and more complaints from our Android app users.

a-maurice commented 1 year ago

I might have figured out the problem, though it depends on how you're testing it. Apparently there is an issue in how the link is "clicked". If you type it in the Chrome app, and navigate to it that way, it will not work, since that counts as Chrome handling it. However, if it is a link on a web page, trigger via Android Studio, or you invoke it via an adb command, like:

adb shell am start -d https://link.vuexr.com/sl/vxrgBbwsXCsYM8nEA

it should work (it might prompt you to determine which app is used to open it). With the app that you shared with me via the GitHub repo, doing that adb command launched the app with the correct info. Going through Chrome's field, it fails.

thesanketkale commented 1 year ago

I might have figured out the problem, though it depends on how you're testing it. Apparently there is an issue in how the link is "clicked". If you type it in the Chrome app, and navigate to it that way, it will not work, since that counts as Chrome handling it. However, if it is a link on a web page, trigger via Android Studio, or you invoke it via an adb command, like:

adb shell am start -d https://link.vuexr.com/sl/vxrgBbwsXCsYM8nEA

it should work (it might prompt you to determine which app is used to open it). With the app that you shared with me via the GitHub repo, doing that adb command launched the app with the correct info. Going through Chrome's field, it fails.

Most of our users have tried clicking the link shared on Whatsapp and Facebook on Android devices (with Android 13 or higher) and observed the issue. Also, opening the link from any web browser is not working for me.

What could be causing this? Is the issue in the Android 13 OS, the dynamic link plugin, or my project?

a-maurice commented 1 year ago

Hmm, it sounds like it will need more direct support then, which hopefully the support ticket can help with. I've tried a handful of devices, including an Android 13 one that is on the latest version, and they all seem to work with both clicking links and this adb method. Did the adb method work for you?

There are a handful of different stackoverflow issues about this type of problem as well, and in one they suggest adding an intent-filter that includes android:pathPrefix="/". https://stackoverflow.com/questions/24808777/deep-linking-intent-does-not-work Again, I didn't have to do this from local testing, but it is something else to try.

thesanketkale commented 1 year ago

@a-maurice, The support agent responded saying everything looks properly configured. See the screenshot below:

image

When you say it worked for you, which project are you referring to? Is it the repro project that I shared with you? Is the repro project working as expected for you on the latest devices you tested with?

FlorianChps commented 1 year ago

Hello @thesanketkale ,

If you still have the problem, check on firebase console your dynamic link details. You'll see there are different host for long and short dynamic link. Add both in your <data in your <intent-filter in your AndroidManifest.xml. It worked for me to add all sub domains in data tag.

a-maurice commented 1 year ago

@thesanketkale Yes, the repro project you shared with me. Clicking links and invoking through ADB both worked for me.

thesanketkale commented 1 year ago

I have tried multiple ways of trying to get it to work, but all in vain. I am stumped. :(

FlorianChps commented 1 year ago

@thesanketkale Did you try what I suggest to you ? Adding all long and short link into your data tag in AndroidManifest.xml where you declared your intent-filter ?

thesanketkale commented 1 year ago

@thesanketkale Did you try what I suggest to you ? Adding all long and short link into your data tag in AndroidManifest.xml where you declared your intent-filter ?

Yes, I did but still no luck.

vjbobeldijk commented 1 year ago

I had a problem with it too, but my xml filters were wrong. The serach parameters in the link url were not being picked up. Now they are with the following. Sorry for my previous mentioned issue, that I deleted.

<intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:scheme="https"
                android:host="www.myapp.com" />
            <!-- Add this line to allow URLs with and without query parameters -->
            <data android:pathPattern="/.*" />
</intent-filter>
thesanketkale commented 1 year ago

I think I solved it. I am able to open the app by clicking on the dynamic links on all devices having Android OS 13 or higher.

The primary issue in my case was an incorrect entry of the SHA certificate fingerprint which has been there since the beginning. I set the fingerprints according to the latest project keystore and voila, it started working.

Another big thing to note was something that was mentioned here and also pointed out to me by @FlorianChps. Initially, I had only put the domains used in the URI prefixes in the AndroidManifest.xml, but instead, I needed to put the domains of the actual links to where the dynamic links forwarded to.

Due to the lack of clear documentation, I have put both kinds of domains in the manifest, the ones used as domain URI prefixes as well as the ones the deep links forward to. And it is working fine as of now.

Thank you all for helping with this issue.