getting Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI] in Android studio 3.0

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>

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


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