Resolving ADB Installation Failure: Analysis and Solutions for INSTALL_FAILED_TEST_ONLY Error

Dec 01, 2025 · Programming · 15 views · 7.8

Keywords: ADB | INSTALL_FAILED_TEST_ONLY | Android installation error

Abstract: This article provides an in-depth exploration of the common ADB installation error INSTALL_FAILED_TEST_ONLY in Android development, analyzing its root cause in the APK's testOnly attribute configuration. By detailing AndroidManifest.xml settings, ADB command parameters, and Android Studio build processes, it offers multiple solutions including modifying manifest attributes, using pm install commands, and adjusting build configurations to help developers quickly diagnose and resolve installation issues.

Problem Background and Error Phenomenon

During Android application development, when using ADB (Android Debug Bridge) to install APK files, developers may encounter the following error message:

adb install <.apk>

After executing this command, the terminal output shows:

5413 KB/s (99747 bytes in 0.017s)
        pkg: /data/local/tmp/AppClient.TestOnly.App3.apk
Failure [INSTALL_FAILED_TEST_ONLY]

This error indicates that ADB successfully recognized the device and transferred the APK file, but the installation was rejected by the system at the installation stage with the error code INSTALL_FAILED_TEST_ONLY. Superficially, this appears to be a simple installation failure, but it actually involves deep-seated logic in Android's security mechanisms and build configurations.

Root Cause Analysis

The root cause of the INSTALL_FAILED_TEST_ONLY error lies in the android:testOnly attribute setting within the APK file. This attribute is defined in the AndroidManifest.xml file, typically within the <application> or <manifest> tags, to indicate whether the APK is intended solely for testing purposes. When the attribute value is set to true, the system restricts the installation methods for this APK, usually allowing installation only via specific debugging tools like ADB, and not through conventional app stores or package managers.

In Android development environments, particularly when using Android Studio for debug builds, the IDE defaults the android:testOnly attribute to true to ensure that the generated APK is used only for development and testing, preventing accidental release to production environments. This design aligns with security best practices but can lead developers to encounter the aforementioned error when attempting to use standard ADB installation commands.

Solution 1: Modify AndroidManifest.xml Configuration

The most direct solution is to modify the android:testOnly attribute in the AndroidManifest.xml file. Developers need to locate this file and find the relevant configuration:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app">
    <application
        android:testOnly="true"
        ...>
        ...
    </application>
</manifest>

Change android:testOnly="true" to android:testOnly="false", or remove the attribute entirely (the default value is false). After modification, rebuild the APK and then use the standard ADB installation command:

adb install AppClient.TestOnly.App3.apk

The installation should now complete successfully. This method is suitable for scenarios where the APK is needed for non-testing purposes, such as internal test distribution or pre-release validation.

Solution 2: Use pm install Command with -t Parameter

If you wish to retain the android:testOnly="true" setting (e.g., in continuous integration testing), you can use Android's package manager (pm) command with the -t parameter. This approach requires first pushing the APK file to the device and then executing the installation via shell. Specific steps are as follows:

First, use the ADB push command to transfer the APK file to a temporary directory on the device:

adb push bin/hello.apk /tmp/
5210 KB/s (825660 bytes in 0.154s)

Then, enter the device environment via ADB shell and use the pm install command. Without the -t parameter, the INSTALL_FAILED_TEST_ONLY error will recur:

adb shell pm install /tmp/hello.apk 
    pkg: /tmp/hello.apk
Failure [INSTALL_FAILED_TEST_ONLY]

After adding the -t parameter, the installation succeeds:

adb shell pm install -t /tmp/hello.apk 
    pkg: /tmp/hello.apk
Success

The -t parameter allows the installation of test-only APKs, bypassing system restrictions. This method is particularly useful for automated testing workflows where the APK's test attributes need to remain unchanged.

Solution 3: Directly Use ADB install Command with -t Parameter

For simplified operations, you can directly use the -t parameter with the ADB install command, eliminating the need for manual file pushing. Assuming the APK file is on the local desktop, the command is as follows:

adb install -t hello.apk

This automatically handles file transfer and installation, successfully installing the test-only APK. This method combines the advantages of the previous solutions, being both convenient and preserving test configurations.

Supplementary Reference: Impact of Android Studio Build Configuration

Based on other developers' experiences, the INSTALL_FAILED_TEST_ONLY error may also be related to Android Studio's build configuration. In Android Studio 3.0 and later versions, APKs built using the "Run" button default to including the android:testOnly="true" attribute, which can prevent installation via conventional methods or submission to app stores.

To generate non-test-only APKs, developers should use the menu option Build > Build APK(s). For debug variants, this produces a debuggable APK that can be installed without ADB; for release variants, it generates an APK suitable for store submission. This design encourages developers to clearly distinguish between test and production builds, reducing the risk of configuration errors.

Summary and Best Practices

The INSTALL_FAILED_TEST_ONLY error is a common issue in Android development, stemming from the APK's android:testOnly attribute setting. Through the analysis in this article, developers can understand the underlying security mechanisms and choose appropriate solutions based on their needs: modify AndroidManifest.xml to remove test restrictions, or use the -t parameter with ADB/pm commands to install test-only APKs. Additionally, pay attention to Android Studio's build processes to ensure APKs are generated correctly when needed.

In practical development, it is recommended to follow these best practices: use test-only APKs with the -t parameter during debugging to maintain environment consistency; before release, generate official APKs via Build > Build APK(s) and verify the android:testOnly attribute settings. This approach enhances development efficiency while ensuring application security and compliance.

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.