【安卓错误】Error while executing: am start -n 解决方案

问题描述

安卓连接真机时编译成功,最后安装时显示失败:
Error while executing: am start -n “com.test.BTClient/com.test.BTClient.MainActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.test.BTClient/.MainActivity }
Error type 3
Error: Activity class {com.test.BTClient/com.test.BTClient.BTClient} does not exist.
【安卓错误】Error while executing: am start -n 解决方案

解决办法:

1)手动卸载app没有卸载干净

adb uninstall packageName命令运行卸载安装包
【安卓错误】Error while executing: am start -n 解决方案
显示卸载成功即可
果然是没有卸载干净的原因,运行adb uninstall 卸载成功后,再次点击Android Studio的运行按钮,成功安装运行。

2)确定applicationId与AndroidManifest.xml中的包名是否一致

【安卓错误】Error while executing: am start -n 解决方案
【安卓错误】Error while executing: am start -n 解决方案
如果不一样,删除defaultConfig下的applicationId,或者将applicationId的值改成manifest文件里指定的package。