22 April 2024 Leave a comment Tech-Help
When working with Android applications, developers often need to install various versions of an APK for testing purposes. However, starting with Android 4.2 (Jelly Bean), attempting to install an older version of an APK over a newer one results in an INSTALL_FAILED_VERSION_DOWNGRADE
error. This safeguard is designed to prevent unintentional downgrades, which could lead to data loss or stability issues. Fortunately, there is a straightforward workaround for bypassing this restriction during development and debugging.
Using the Allow Downgrade Option
To install an APK with a lower version number over an existing application without uninstalling it, you can use the -d
flag with the adb install
command. This flag stands for “allow downgrade” and permits the installation of older versions without error.
Here is the command you can use:
adb install -r -d your-app.apk
The -r
flag indicates that the existing app should be replaced, and the -d
flag allows for downgrading the version.
Alternative Method: Uninstalling the Application First
If for some reason the above method does not work, you can always uninstall the existing application first before installing the older version. Here’s how you can do it:
adb uninstall com.package.name
After uninstalling, you can proceed with the regular installation of your APK:
adb install your-app.apk
Note that uninstalling the application will remove all associated data unless the -k
flag is used, which keeps the data and cache directories:
adb uninstall -k com.package.name
Considerations for System Apps
If the application you are working with is a system app, you’ll need to include the -t
flag to allow test packages:
adb install -t -r -d your-app.apk
Streamlining Your Testing with Repeato
While the methods above are helpful for manual testing, automating your tests can save a significant amount of time and effort. This is where Repeato, a no-code test automation tool, can be particularly beneficial. Repeato simplifies the creation, execution, and maintenance of automated tests for your Android and iOS apps, supporting various app frameworks like React Native, Flutter, and Unity.
With its computer vision and AI capabilities, Repeato allows for rapid test editing and execution. It also includes ADB onboard, enabling you to execute ADB commands directly within your test scripts through “script steps”. This seamless integration means you can automate even complex testing scenarios, ensuring that your app consistently performs at its best across different versions and devices.