[android] ADB Install Fails With INSTALL_FAILED_TEST_ONLY

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?

This question is related to android installation apk adb

The answer is


If you want to test the apk, just add the -t command line option.

Example command:

adb install -t .\app-debug.apk

Android 3.6.2.

Build >> Build/Bundle apk >> Build apk

Its working fine.enter image description here


As mentioned in documentation:

Android Studio automatically adds this attribute when you click Run

So, to be able to install your apk with adb install <path to apk file> you need to assemble build from terminal: ./gradlew assembleDebug and install with adb. Or just run ./gradlew installDebug to build and install on the device simultaneously.


this works for me adb install -t myapk.apk


I tried external project, with multiple apk.

The command from Studio, looked like

adb install-multiple -r ....

Solution -

  • select console
  • aste command with -t

I don't know if it's gonna be useful for anyone or not, but I got this error message, when I accidentally tried to build and install my project with test gradle plugin ('gradle:2.4.0-alpha5') version in stable Android Studio version (2.3, not in 2.4 preview 5 version I'd downloaded and installed before).

When I realized my mistake, I launched preview Android Studio version and it built and installed my project without any problem.


None of the previous post solve my issue. Here is what's happening with me:
I normally load the app from android studio by clicking on the "Run" button. When you do this, android would create an app that's good for debug but not for install. If you try to install using:

adb install -r yourapk

you will get a message that says:

Failure [INSTALL_FAILED_TEST_ONLY]

When this happens, you will need to rebuilt the apk by first clean the build, then select Build->Build APK. See the image bellow:

build android apk

This APK is ready to be installed either through adb install command or any other methods

Hope this helps

David


The easiest to solve this, without reverting to an older gradle version is to add the '-t' option in the run configurations (for pm install).

testOnly='false' had no effect whatsoever. The error is caused by the alpha version of gradle plugin that makes debug APK 'for test only purposes'. The -t option allows such APK to be installed. Setting it in run configuration makes it automatically install you APK as usual.


What worked for me is performing Refresh all Gradle projects from the Gradle toolbar from the right menu.

PFB the screenshot from Android Studio.

  1. Select Gradle toolbar from the right menu.
  2. Select the Refresh icon

This resolved the issue for me.

Screenshot from Android Studio


I see the accepted answer but you dont have to actually push the apk and then run the command on adb shell direct adb install with -t flag actually works

adb install -t "path to apk in ur computer"

attaching a screenshot for reference enter image description here


I agree with Elisey. I got this same error after opening my project in the 2.4 preview and then opening the same project in android studio 2.3

Fixed the issue by changing this line in build.gradle from

classpath 'com.android.tools.build:gradle:2.4.0-alpha5'

to

classpath 'com.android.tools.build:gradle:2.3.1'

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.


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


Although I am sure Saurabh's answer will work for most other people, I did want to identify the extra steps I had to take in order to get my apk installed.

I tried pushing to the device with the following result:

? adb push AppClient.TestOnly.App3.apk \tmp\
failed to copy 'AppClient.TestOnly.App3.apk' to '\tmp\': Read-only file system

After looking around to change the filesystem RW permissions I ended up executing the following commands:

? adb shell
255|shell@android:/ $ su
shell@android:/ # mount -o remount,rw /
mount -o remount,rw /

I got this when I tried to push again:

? adb push AppClient.TestOnly.App3.apk /tmp
failed to copy 'AppClient.TestOnly.App3.apk' to '/tmp': Permission denied

I was able to push to the sdcard:

? adb push AppClient.TestOnly.App3.apk /sdcard/
3178 KB/s (99747 bytes in 0.030s)

At which point I was able to execute Saurabh's command:

shell@android:/ # pm install -t /sdcard/AppClient.TestOnly.App3.apk
pm install -t /sdcard/AppClient.TestOnly.App3.apk
        pkg: /sdcard/AppClient.TestOnly.App3.apk
Success

My finding is as below. If I compile using the Android Studio UI, and the APK generated, I can't just

adb install <xxx.apk>

It will generate Failure [INSTALL_FAILED_TEST_ONLY]

I need to compile it using the gradle i.e. ./gradlew app:assembleRelease. Then only the generated apk, then it can only be installed.

This is because the Android Studio UI Compile, only generate test apk for a particular device, while ./gradlew app:assembleRelease command is the actual apk generation to be installed on all device (and upload to playstore)


For me it has worked execute the gradle task 'clean' (under :app, at Gradle pane, usually located at the right) and run again the project.


add this line to your ‘gradle.properties’

android.injected.testOnly=false

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

answer is in the red box


first remove the unstable version:

adb uninstall problematic-package-name

; and then reinstall the apk.


In my case was by uploading an APK, that although it was signed with production certificate and was a release variant, was generated by the run play button from Android studio. Problem solved after generating APK from Gradle or from Build APK menu option.


In my case, using Android Studio 4.0, the below solved the issue;

Add to 'gradle.properties' file;

android.injected.testOnly=false 

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

android.injected.testOnly=false

to the gradle.properties file


Android studio 3.0 generates test only APK.

I have solved the issue by adding the "android:testOnly" property to android manifest's tag.

 <application
    .....
    android:testOnly="false"
    android:theme="@style/AppTheme">

And then generated the APK by Android studio3.0 menu:Build-->Build APK(s).

More Info: https://commonsware.com/blog/2017/10/31/android-studio-3p0-flag-test-only.html


Build your distribution .apk from Android Studio as follow

Build --> Build Apk(s) (for unsigned build) Build --> Generate Signed APK ( for signed build)

These option builds the APK with android:testOnly="false" option which allows you to install the APK expicitly into device by the commond.

adb install yourBuilT.apk


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to installation

You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) Conda version pip install -r requirements.txt --target ./lib How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" PackagesNotFoundError: The following packages are not available from current channels: Tensorflow import error: No module named 'tensorflow' Downgrade npm to an older version Create Setup/MSI installer in Visual Studio 2017 how to install tensorflow on anaconda python 3.6 Application Installation Failed in Android Studio How to install pip for Python 3.6 on Ubuntu 16.10?

Examples related to apk

Application Installation Failed in Android Studio Difference between signature versions - V1 (Jar Signature) and V2 (Full APK Signature) while generating a signed APK in Android Studio? Session 'app': Error Installing APK Android Error Building Signed APK: keystore.jks not found for signing config 'externalOverride' Build and Install unsigned apk on device without the development server? The APK file does not exist on disk Android Studio: Application Installation Failed How to retrieve Key Alias and Key Password for signed APK in android studio(migrated from Eclipse) ADB Install Fails With INSTALL_FAILED_TEST_ONLY Upload failed You need to use a different version code for your APK because you already have one with version code 2

Examples related to adb

ADB server version (36) doesn't match this client (39) {Not using Genymotion} ADB device list is empty "unable to locate adb" using Android Studio Run react-native on android emulator Solving "adb server version doesn't match this client" error Adb install failure: INSTALL_CANCELED_BY_USER Session 'app': Error Installing APK Where is adb.exe in windows 10 located? How to debug in Android Studio using adb over WiFi Set adb vendor keys