[Fixed] Android: Failed to measure fs-verity, errno 1 when updating app from code – Android

by
Maya Patel
android android-intent auto-update kotlin viewmodel

The Problem:

In an Android app, there is a feature to update the app via an external link to the APK with the new version. The user downloads the APK from the external link and uses the packageInstaller to update the app. The update is successful, but after the update, the app crashes with the error: “Failed to measure fs-verity, errno 1: /data/app/~~QTV2DULtWFYdJpO7yGn7sg==/com.test.app–JKzM4i9A3BAuvFAm9x9YQ==/base.apk”. How can this error be resolved?

The Solutions:

Solution 1: Handle App Update Completion with Broadcast Receiver

Solution Title: Handling App Update Completion with Broadcast Receiver

The issue arises because the app attempts to launch immediately after the update installation, while the system is still performing post-installation tasks. This can lead to the “Failed to measure fs-verity, errno 1” error. To resolve this, you can introduce a broadcast receiver to handle the completion of the app update process.

  1. Create a Broadcast Receiver:
    • Define a custom broadcast receiver class that extends BroadcastReceiver.
    • Implement the onReceive() method in the receiver class, which will be called when the update process is complete.
  2. Register the Receiver:
    • In your AndroidManifest.xml file, declare the broadcast receiver with an intent filter for the “com.android.vending.INSTALL_REFERRER” action.
  3. Send Broadcast on App Update Completion:
    • When the app update process is complete, send a broadcast with the “com.android.vending.INSTALL_REFERRER” action using PendingIntent.
  4. Handle Broadcast in Receiver:
    • In the onReceive() method of your broadcast receiver, handle the received broadcast and perform necessary actions, such as launching the updated app or displaying a notification.

Code Snippet:
Here’s an example of how to implement the broadcast receiver:

class PackageInstallerStatusReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
        Log.d("UPD!", "APP HAS BEEN UPDATED!")

        if (context == null) {
            Log.d("ERR!", "Context should not be null")
            return
        }

        val stIntent = Intent(context, MainActivity::class.java)
        startActivity(context, stIntent, null)
        return
    }
}

In your AndroidManifest.xml file, add the following:

<receiver android:name=".PackageInstallerStatusReceiver">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

With this approach, you can handle app update completion explicitly through the broadcast receiver, allowing the system to properly finalize the installation process before launching the updated app.

Q&A

What could be the reason behind the error "Failed to measure fs-verity, errno 1" when updating an Android app from code?

The error may occur due to security mechanisms in Android 13, even if the app update is successful.

How can the user experience be improved during the app update process?

Adding a broadcast receiver to launch the main activity after the app update can create a seamless transition for the user.

Video Explanation:

The following video, titled "Annoying error problem when exporting Android APK file from Unity ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

I got these annoying errors: - Starting a Gradle Daemon, 1 incompatible Daemon could not be reused - FAILURE: Build failed with an exception ...