adb install INSTALL_FAILED_TEST_ONLY的原因

给测试同学打了个deubg包发现无法安装,提示无法解析,使用adb install安装后提示INSTALL_FAILED_TEST_ONLY,原来是Android Studio 3.0会在debug apk的manifest文件application标签里自动添加android:testOnly="true"属性

在Android Studio进行开发的时候,生成的debug apk手动使用adb install无法安装,提示错误:

问题

➜  apk adb install '/home/yezhou/demo/demo-debug.apk' 
adb server is out of date.  killing...
* daemon started successfully *
5347 KB/s (8758206 bytes in 1.598s)
    pkg: /data/local/tmp/demo-debug.apk
Failure [INSTALL_FAILED_TEST_ONLY]

分析

但是使用Android Studio开发过程中发现可以直接安装成功。经过查询资料发现在AndroidManifest.xml文件中添加了属性testOnly=true,参考:https://developer.android.com/guide/topics/manifest/application-element

反编译当前apk发现清单文件中的确新加了这个属性,研究发现原来是Android Studio 3.0会在debug apk的manifest文件application标签里自动添加android:testOnly="true"属性,导致IDE中run跑出的apk在大部分手机上只能用adb install -t来安装。

解决方法

方法一:在项目中的gradle.properties全局配置中设置:

android.injected.testOnly=false

方法二,加-t参数:

adb install -t app-debug.apk

通过方法一设置后,反编译后没有属性testOnly=true

上一篇 Glide 4.0梳理
下一篇 Glide 4.x生成GlideApp
目录
文章列表
1 Docker搭建私有仓库
Docker搭建私有仓库
2
Docker使用swarm创建集群
Docker使用swarm创建集群
3
Spring Boot整合EhCache
Spring Boot整合EhCache
4
Flutter中showModalBottomSheet点击内容区域自动关闭Dialog解决
Flutter中showModalBottomSheet点击内容区域自动关闭Dialog解决
5
编写自己的Spring Boot Starter
编写自己的Spring Boot Starter
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。