ADB Install Fails With INSTALL_FAILED_TEST_ONLY

159,527

Solution 1

Looks like you need to modify your AndroidManifest.xml
Change android:testOnly="true" to android:testOnly="false" or remove this attribute.

If you want to keep the attribute android:testOnly as true you can use pm install command with -t option, but you may need to push the apk to device first.

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

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

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

I was able to reproduce the same issue and the above solved it.

If your APK is outside the device (on your desktop), then below command would do it:

$ adb install -t hello.apk

Solution 2

I had a similar problem with Android Studio 3.0.0 Beta 7 and could not publish anymore to the play store.

As stated here: https://developer.android.com/studio/run/index.html

Note: The Run button builds an APK with testOnly="true", which means the APK can only be installed via adb (which Android Studio uses). If you want a debuggable APK that people can install without adb, select your debug variant and click Build > Build APK(s).

Same goes for release build, with Android Studio 3 you need to go to Build > Build APK(s) to have a non testable release apk that you can submit to the store.

Solution 3

Add -t install flag, as on the screenshot below:

answer is in the red box

Solution 4

In my case this mistake was in unstable gradle version. Just use a stable version of gradle (not alpha, not even beta). And it was fixed for me

Solution 5

After searching and browsing all day, the only one works is adding

android.injected.testOnly=false

to the gradle.properties file

Share:
159,527

Related videos on Youtube

evve
Author by

evve

Updated on July 19, 2022

Comments

  • evve
    evve almost 2 years

    I am having issues installing an apk to my device.

    adb install <.apk>
    

    Using the above command returns the following:

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

    Any idea on what might cause this issue?

    It definitely recognizes the device. Could it be an issue with the apk?

  • evve
    evve almost 10 years
    I should add that some of this may not be necessary for others.
  • Saurabh Meshram
    Saurabh Meshram almost 10 years
    Appreciate the extra effort!.
  • Reaz Murshed
    Reaz Murshed about 7 years
    Saved the day! Changed the gradle version from 2.4.0-alpha3 to 2.3.0
  • Ryan R
    Ryan R almost 7 years
    The price of sticking to the bleeding edge... Thanks!
  • BubbaGum
    BubbaGum almost 7 years
    The sample project I compile use 'com.android.tools.build:gradle:2.4.0-alpha7' and does not compile with a stable version, only adding -t as mentioned solved the issue for me.
  • rmtheis
    rmtheis over 6 years
    Please explain what -t does.
  • xiaoyee
    xiaoyee over 6 years
    in adb help, you will see install with -t means allow test packages
  • GPS
    GPS over 6 years
    Can anyone confirm that setting android:testOnly="true" will fix it for unstable gradle versions too?
  • marioc64
    marioc64 over 6 years
    You don't need to adb push and pm install, you can specify the -t switch just after the adb install command: adb install -t -r package.apk
  • Sky Kelsey
    Sky Kelsey over 6 years
    This started happening with Android Studio 3.0, and your suggestion fixed it for me.
  • noamtm
    noamtm over 6 years
    I suspect that right now (Oct/Nov 2017) this is the correct answer for most people who get here. Before AS 3, the APK produced by "Run" was installable even outside of AS, no it is not.
  • Gene Bo
    Gene Bo over 6 years
    screen is launched via clicking Edit Configurations on the module dropdown menu - between Make and Run, Debug buttons at top of IDE : developer.android.com/studio/run/rundebugconfig.html
  • Elye
    Elye over 6 years
    Refers to medium.com/@elye.project/… to understand better of the issue.
  • Basim Sherif
    Basim Sherif about 6 years
    Thanks! This will fix spoon runner issue as well!
  • amIT
    amIT about 6 years
    no need to push the apk anymore adding -t works in adb install works fine , for the full command check my answer below.
  • user3193413
    user3193413 almost 6 years
    Thanks mate. It started after upgrading android gradle to 4. Deploying the app directly from android studio works fine but not if using the terminal (adb install etc..) After refreshing the gradle as you mentioned it worked.
  • sunil
    sunil almost 6 years
    @user3193413 Nice to hear the post was of help
  • ruben
    ruben over 5 years
    there's update and there's some more tweak.. took me a while to figure it out :/
  • drulabs
    drulabs over 4 years
    You are a lifesaver. I was having trouble with the release build (faulty keystore) and wanted to distribute debug builds to my testers.
  • HendraWD
    HendraWD over 4 years
    adb push bin/hello.apk /tmp/ doesn't work for me, adb push ./debug.apk /sdcard/temp/debug.apk worked
  • Joshua Pinter
    Joshua Pinter over 4 years
    If you're using appium, you need to specify "allowTestPackages": "true" to your e2e scheme capabilities.
  • Sulav Timsina
    Sulav Timsina over 4 years
    adb install -t app/build/outputs/apk/usUnitedStates/debug/app-usUnited-debu‌​g.apk worked for me.
  • Julian
    Julian about 4 years
    Thanks. That solved my problem. My app was a system app. Thus -f was needed. -f: Install package on the internal system memory.
  • Girish
    Girish almost 4 years
    @JoshuaPinter Can you please elaborate where to put allowTestPackages": "true"
  • Joshua Pinter
    Joshua Pinter almost 4 years
    @Girish You add it to your Appium driver config, like config.allowTestPackages = true. Note, this only pertains to end to end tests using Appium.
  • Prahlad V Thej
    Prahlad V Thej almost 3 years
    @nicklee Would I be able to release this build on play-store with key set as android.injected.testOnly = false or should I revert it back to "true" when I am uploading to play-store?
  • Prahlad V Thej
    Prahlad V Thej almost 3 years
    Would I be able to release this build on play-store with key set as android.injected.testOnly = false or should I revert it back to "true" when I am uploading to play-store?
  • Martin
    Martin almost 3 years
    The android:testOnly="true" is only set in the build/intermediates/**/AndroidManifest.xml files. So I never added the flag in the first case.
  • Martin
    Martin almost 3 years
    @prahlad-v-thej Pretty sure the opposite is true: Trying to upload an testOnly version to the Play-Store will fail. My suspicion is that Google added testOnly so you don't accidentally upload a version meant for debugging and testing to the store. Since I make clean builds before upload it doesn't matter to me.
  • Martin
    Martin almost 3 years
    No, that doesn't work — my test scripts do an uninstall automatically when the install fails.
  • Reza
    Reza over 2 years
    Perfect. you saved my time. I had the same problem that I sent debug apk in outputs folder of project. I didn't know that I should build it using BUILD APK
  • android developer
    android developer almost 2 years
    This works, but then of course the app is more limited in terms of developing it... :(