getting Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI] in Android studio 3.0

AndroidAndroid StudioApk

Android Problem Overview


As per this blogpost from CommonsWare, AndroidManifest.xml file can have an android:testOnly attribute.

In my AndroidManifest.xml it is set as "false"

android:testOnly="false"

And I am generating the apk file using the “Build APK(s)” menu option as shown below image,

enter image description here

And when i am trying to install app from command line, adb install -r myapp.apk, I am still getting error,

> Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]

Android studio version is as below, enter image description here

What else shall I do to make my app run?

Android Solutions


Solution 1 - Android

You can also use command like this :

adb install -r -t myapp.apk

it works for me:

PS C:\Users\languoguang> adb -P 12345 install -r D:\GreeneTrans\HelloWorld-signed.apk
adb: failed to install D:\GreeneTrans\HelloWorld-signed.apk: Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]
PS C:\Users\languoguang> adb -P 12345 install -t D:\GreeneTrans\HelloWorld-signed.apk
Success
PS C:\Users\languoguang> adb -P 12345 install -r -t D:\GreeneTrans\HelloWorld-signed.apk
Success
PS C:\Users\languoguang>

Solution 2 - Android

Just use the following command:

adb install -t app/build/outputs/apk/debug/app-debug.apk

You do not need to use -r, -r means Reinstall an existing app, keeping its data.

> Install an app You can use adb to install an APK on an emulator or > connected device with the install command: > > adb install path_to_apk > > You must use the -t option with the install command when you install a > test APK. For more information, see -t.

https://developer.android.com/studio/command-line/adb#move

> -t: Allow test APKs to be installed. Gradle generates a test APK when you have only run or debugged your app or have used the Android Studio > Build > Build APK command. If the APK is built using a developer > preview SDK (if the targetSdkVersion is a letter instead of a number), > you must include the -t option with the install command if you are > installing a test APK.

https://developer.android.com/studio/command-line/adb#-t-option

Or you could use the same command as you click Run in Android Studio

adb push {project dir}/app/build/outputs/apk/debug/app-debug.apk /data/local/tmp/{appId}

adb shell pm install -t /data/local/tmp/{appId}

appId is defined in the app/build.gradle.

defaultConfig {
    applicationId appId

Now the app is installed from locally on the device Launch the first activity.

adb shell am start -n "{package name}/{package name}.splash.SplashActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

> 2019-11-13 13:43 Gradle sync started > > 13:44 Project setup started > > 13:44 Executing tasks: [:app:generateDebugSources, > :vplus_explore:generateDebugSources, > :vplus_uibase:generateDebugSources, > :vplus_widget:generateDebugSources, > :vplus_runtime:generateDebugSources, > :vplus_cards:generateDebugSources, > :vplus_launcher:generateDebugSources, > :vplus_settings:generateDebugSources, > :vplus_transactions:generateDebugSources, > :vplus_payment:generateDebugSources, > :vplus_common:generateDebugSources, > :vplus_account:generateDebugSources, > :vplus_commonres:generateDebugSources, > :vplus_bootstrap:generateDebugSources, > :vplus_logger:generateDebugSources] > > 13:44 Gradle sync finished in 27 s 126 ms > > 13:44 Gradle build finished in 4 s 666 ms > > 13:45 * daemon not running; starting now at tcp:5037 > > 13:45 * daemon started successfully > > 13:45 Executing tasks: [:app:assembleDebug] > > 13:46 Gradle build finished in 33 s 640 ms

Solution 3 - Android

If you really want to be able to remove the test flag from the APK generated in Android Studio, you could try adding the following to your gradle.properties file:

> android.injected.testOnly = false

Solution 4 - Android

Solution 1

Click drop-down menu with your configuration and choose Edit Configurations…

Edit Configurations…

Select tab General and add -t to Install Flags field. Click Ok.

Install Flags

Now start the application again and it should work.

Solution 2

> This means that, the shared application has some test packages, so > unless those has been removed and source is recompiled, you will not > be able to install this apk. But adb command provides a flag “-t” > using which you can install the apps with test packages.

$ adb install -r -t YourAndroidApp.apk
2566 KB/s (7266004 bytes in 2.764s)
Success

Solution 3

This error might occur if you moved the project from other computer where it was stored in different directory. To resolve the problem: Clean the project and build it again.

Solution 4

Go to “Settings” -> “Build, execution, deployment” and disable “instant run to hot swap code…”

Solution 5 Add this line to gradle.properties:

android.injected.testOnly = false

Solution 5 - Android

If you would like to manually install an APK or give it to someone for manual installation using the following adb command, then you should only build the APK from the Menu bar -> Build -> Build Bundle/APK.

 adb install -r xyz.apk

Do not click on the play button as it builds the APK for test purposes only. Clicking on the play button overrides the APK in the default location which can then be installed manually by using the following command only.

adb install -r -t xyz.apk

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAADProgrammingView Question on Stackoverflow
Solution 1 - AndroidLanguoguangView Answer on Stackoverflow
Solution 2 - AndroidFrancis BaconView Answer on Stackoverflow
Solution 3 - AndroidRobDView Answer on Stackoverflow
Solution 4 - AndroidMasoud MokhtariView Answer on Stackoverflow
Solution 5 - AndroidManasView Answer on Stackoverflow