Resolving ADB Install Failure: Analysis and Fix for INSTALL_CANCELED_BY_USER Error on Xiaomi Devices

Dec 07, 2025 · Programming · 9 views · 7.8

Keywords: ADB install failure | INSTALL_CANCELED_BY_USER | Xiaomi device permissions

Abstract: This article provides an in-depth analysis of the INSTALL_CANCELED_BY_USER error encountered when installing applications via ADB on Xiaomi devices. By examining log files, the root cause is identified as MIUI's permission management system. The paper details the error origins and offers solutions based on the best answer, including enabling the "Install via USB" option in Security apps or Developer Options. Additional factors and preventive measures are discussed to assist developers in efficiently resolving similar issues.

Background and Error Phenomenon

In Android development, installing applications via ADB (Android Debug Bridge) is a common task, but developers may encounter installation failures. For example, when running the command ./adb -d install /path/to/android-debug.apk -r -g on a Xiaomi MI5 device, the output shows successful transfer but returns Failure [INSTALL_CANCELED_BY_USER]. Users report that the device is idle with no active operations, developer mode is enabled, yet the installation is canceled.

Log Analysis and Core Issue

From the provided adb logcat logs, key lines reveal the problem source:

06-06 10:04:21.066  4553  4553 W asset   : Asset path /data/local/tmp/android-debug.apk is neither a directory nor file (type=0).
06-06 10:04:21.066  4553  4553 D AdbInstallActivity:  parsePackage is null , path :/data/local/tmp/android-debug.apk

These logs indicate that MIUI's security center component, AdbInstallActivity, fails to parse the APK file, even though it was successfully transferred to the device. Further analysis shows that MIUI systems (e.g., MIUI 7.2.13) default to restricting USB-based installations to enhance security. This leads to the installation request being intercepted by the system, returning a user-canceled error, even without user intervention.

Solution: Enabling the "Install via USB" Option

Based on the best answer (score 10.0), the core step to resolve this issue is enabling the "Install via USB" feature on MIUI devices. The method varies by MIUI version:

  1. For older MIUI versions (e.g., MIUI 7):
    • Open the "Security" app.
    • Tap the "Options" button in the top-right corner.
    • Scroll to the "Feature Settings" group and find "Permissions".
    • Disable the "Install via USB" option (note: descriptions may vary by translation; ensure the feature is enabled to allow installations).
  2. For newer MIUI versions (e.g., Redmi devices):
    • Go to "Settings" > "Additional Settings" > "Developer Options".
    • Locate the "Install via USB" option and enable it (i.e., toggle it on).

After enabling this option, the system should permit ADB installations, and the error should be resolved. A supplementary answer (score 2.7) confirms similar steps, but the best answer provides more detailed context and version differences.

In-Depth Technical Analysis and Code Examples

From a programming perspective, this error involves Android system permissions and package management mechanisms. When ADB sends an installation request, the system invokes the PackageManager service, but in MIUI, this process is intercepted by security center components. Below is a simplified code example illustrating how to simulate installation via ADB commands, though actual implementation requires system permissions:

// Example: Installing an APK via ADB command (to be executed in terminal)
String adbCommand = "adb install -r /path/to/app.apk";
// In code, this can be executed via Runtime.exec(), but permission errors must be handled
// For instance, in Android apps, permission to install from unknown sources may be required

On MIUI devices, even with a valid APK file, system security policies (e.g., SELinux policies) may block installations. The AVC (Access Vector Cache) denial messages in the logs (e.g., avc: denied { search }) hint at permission issues, but the primary conflict lies in the user-configurable "Install via USB" switch.

Other Potential Factors and Preventive Measures

Beyond the above solution, developers should consider the following factors:

For developers using cross-platform frameworks like Ionic, encountering the same error when running ionic run android typically stems from this system restriction. Once resolved, the command should execute normally.

Conclusion

The INSTALL_CANCELED_BY_USER error on Xiaomi devices is primarily caused by MIUI's security features. By enabling the "Install via USB" option, developers can bypass system restrictions and successfully install applications. This article, based on the best answer from the Q&A data, provides detailed analysis and steps to help developers quickly diagnose and resolve similar issues. In practical development, understanding device-specific behaviors is crucial for efficient debugging.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.