Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android applinks not working in released build but work correctly from a local install

I have a game that is using applinks. The applinks work fine when running debug and release versions from my computer but don't work for the version downloaded from Google Play. With the Google Play version, I get a dialog asking which app should open the link.

I use "App Signing by Google Play" and understand that the release APK is signed by Google and has a different signature. I've added the SHA-256 certificate fingerprint from the app signing certificate listed on Google Play to my assetlinks.json so it contains the fingerprint from both the local and Google Play versions.

I've also downloaded a derived APK from Google Play and made sure that the fingerprint matches that in the assetlinks.json file.

Here's an example URL, that when clicked in Android should open the app, which it does for a local build, but not in the Google Play version. Instead, I get a dialog asking which app should open the link.

https://letsdraw.fun/ec?parent=Z0ibN7m-H8jO1jCiMRQtY23VTpKjnIch

I'm writing out the SHA256 fingerprint in logcat from the live release version to double check it's correct and it all looks fine.

The original signed APK and Google Play signed APK can be downloaded from here. Both of these APKs were downloaded from Google Play, one "original" and one "derived", so they should be identical apart from the signing. Interestingly, they're slightly different sizes. 11,590,297 bytes vs 11,601,619 bytes.

Looking at the output from adb shell dumpsys package domain-preferred-apps the original signed apk is

  Package: com.scribble.exquisitecorpse
  Domains: letsdraw.fun scribble-cloud.appspot.com scribble-cloud-v24-test-dot-scribble-cloud.appspot.com
  Status:  always : 200000000

Whereas the Google Play signed apk is

  Package: com.scribble.exquisitecorpse
  Domains: letsdraw.fun scribble-cloud.appspot.com scribble-cloud-v24-test-dot-scribble-cloud.appspot.com
  Status:  ask

When testing with the test page mentioned by @ymindstorm

https://developers.google.com/digital-asset-links/tools/generator

I get the message

Success! Host letsdraw.fun grants app deep linking to com.scribble.exquisitecorpse.

Do you have any suggestions as to what could be causing this?

Update: I've now reported this to Google as a bug, as I can't work out what's going on. https://issuetracker.google.com/issues/162564916

like image 383
Will Calderwood Avatar asked Jul 19 '20 05:07

Will Calderwood


People also ask

Why can’t I open links in Android apps?

However, some users report that they can’t open links in Android apps. If you are among them, don’t worry, because we have a way to solve this in a matter of minutes. Why can’t I open links on Android? If you can’t open links on Android apps, make sure to check in-app settings, reinstall the app, or inspect in-app permissions.

What are Android app links and how do they work?

Android App Links are a special type of deep link that allow your website URLs to immediately open the corresponding content in your Android app (without requiring the user to select the app).

Why is my Android app link not verifiable?

This behavior protects your app's security. Check whether your server can connect to your client apps. For testing purposes, you might intentionally add non-verifiable links. Keep in mind that, on Android 11 and lower, these links cause the system to not verify all Android App Links for your app.

How do I add Android app links to my App?

To add Android App Links to your app, define intent filters that open your app content using HTTP URLs (as described in Create Deep Links to App Content ), and verify that you own both your app and the website URLs (as described in this guide).


1 Answers

I got help from Google eventually... it wasn't a bug.

The build process was merging in the host from the network_security_config.xml file, so even though the AndroidManifest.xml file specified:

        <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="letsdraw.fun" android:pathPrefix="/ec" android:scheme="https" />
            <data android:host="letsdraw.fun" android:pathPrefix="/restore" android:scheme="https" />
        </intent-filter>

The file from the build process specified other hosts too:

        <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="http"
                android:host="scribble-cloud-v24-test-dot-scribble-cloud.appspot.com"
                android:pathPrefix="/ec" />

            <data
                android:scheme="https"
                android:host="scribble-cloud.appspot.com"
                android:pathPrefix="/ec" />

            <data
                android:scheme="https"
                android:host="letsdraw.fun"
                android:pathPrefix="/ec" />

            <data
                android:scheme="https"
                android:host="letsdraw.fun"
                android:pathPrefix="/restore" />
        </intent-filter>

On this page it states that

Only if the system finds a matching Digital Asset Links file for all hosts in the manifest does it then establish your app as the default handler for the specified URL patterns.

The problem was that my test host was not returning the same assetlinks.json file as the other hosts.

After building your APK, using IntelliJ or Android Studio go to Build | Analyze Apk and open the just built APK to check your hosts are all correct and the assetlinks.json file is returning the correct signatures.

Why is it merging the manifest file like this? Hopefully, we'll find out here!

like image 183
Will Calderwood Avatar answered Oct 20 '22 10:10

Will Calderwood