在 Android studio 3.0 中获取失败 [INSTALL_FAILED_TEST_ONLY: installPackageLI]

getting Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI] in Android studio 3.0

根据来自 CommonsWare 的 blogpostAndroidManifest.xml 文件可以有一个 android:testOnly 属性。

在我的 AndroidManifest.xml 中设置为 "false"

android:testOnly="false"

我正在使用“Build APK(s)”菜单选项生成 apk 文件,如下图所示,

当我尝试从命令行安装应用程序时,adb install -r myapp.apk,我仍然遇到错误,

Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]

Android工作室版本如下,

我还应该做些什么来制作我的应用程序 运行?

如果您确实希望能够从 Android Studio 中生成的 APK 中删除测试标志,您可以尝试将以下内容添加到您的 gradle.properties 文件中:

android.injected.testOnly = false

您也可以使用这样的命令:

adb install -r -t myapp.apk

对我有用:

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>

只需使用以下命令:

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

您不需要使用 -r,-r 表示重新安装现有应用程序,并保留其数据。

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

或者您可以在 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 定义在 app/build.gradle.

defaultConfig {
    applicationId appId

现在应用程序是从设备本地安装的 启动第一个 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

解决方案 1

单击包含您的配置的下拉菜单并选择 Edit Configurations…

Select 选项卡常规并将 -t 添加到 Install Flags 字段。单击确定。

现在再次启动应用程序,它应该可以工作了。

解决方案 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

解决方案 3

如果您将项目从存储在不同目录的其他计算机上移走,则可能会发生此错误。解决问题:Clean the project 并重新构建它。

解决方案 4

转到“Settings”->“Build, execution, deployment”并禁用“instant run热插拔代码...”

解决方案 5 将此行添加到 gradle.properties:

android.injected.testOnly = false

如果您想使用以下 adb 命令手动安装 APK 或将其提供给其他人进行手动安装,那么您应该只从菜单栏构建 APK -> 构建 -> 构建 Bundle/APK .

 adb install -r xyz.apk

请勿点击播放按钮,因为它构建的 APK 仅用于测试目的。单击播放按钮会覆盖默认位置中的 APK,然后只能使用以下命令手动安装。

adb install -r -t xyz.apk