使用Android Studio通过USB连接时无法在手机上运行/调试应用(安装时会断开连接) [英] Can't run/debug app on phone while connected through USB while using Android Studio (it disconnects when installing)

查看:114
本文介绍了使用Android Studio通过USB连接时无法在手机上运行/调试应用(安装时会断开连接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序在Nexus 5(Android 6)和LG Stylus 2 Plus(Android 8)手机上通过Android Studio通过USB连接时完全能够运行/调试,但在测试时似乎无法通过在我的华为P30(Android 9)上.

我能够从Android Studios的设备文件资源管理器"标签中查看所有3台设备,并浏览其中的文件,因此我知道它可以正常连接.

不过,无论何时,当我尝试在华为上调试或运行该应用程序时,该应用程序都会生成,并且一旦开始安装过程,手机就会断开连接并立即重新连接到PC,从而导致尝试安装失败.

我从Android Studio中只能看到以下消息:

 安装未成功.无法安装该应用程序.由于以下原因安装失败:'找不到设备'ABCDEFGHIJKLM' 

我确实没有找到适合华为P30的驱动程序,但是我相信,如果现在能够查看手机的文件,那么这应该不再是驱动程序问题.

我尝试了在电话的开发人员选项中进行的所有电话配置,但我发现这些配置无效.

解决方案

TL; DR:

这两个android工具的版本已过时:

  • Android SDK构建工具

  • Android SDK平台工具

将所有android工具更新到最新版本,并确保没有旧的工具徘徊,您应该一切顺利. =)


尝试将APK从Android Studios的设备文件资源管理器"直接上传到手机中后,标签,并且以相同的方式失败,我知道 adb-server 出了点问题.因此,我继续使用以下命令从控制台直接运行 adb :

  $ adb启动服务器$ adb push abcdefg.apk 

服务器启动正常,并导致相同的行为,但这向我显示了一条新的错误/警告消息,从未在Android Studio中显示过:

  adb服务器版本(30)与该客户端(41)不匹配;杀死... 

这足以让我找到这样的问题和博客文章:

现在,非常重要,请卸载您可能拥有的任何旧版本的工具,以免这些工具被使用(因为它确实发生在过程).您可以通过点击显示包裹详细信息"来检查它复选框,并且仅检查最新版本:

此后,从任务管理器中杀死 adb (如果正在运行),然后重新启动Android Studio.这应该确保您没有使用任何旧版本.

I got an app that I'm perfectly able to run/debug while connected through USB from Android Studio on my Nexus 5 (Android 6) and LG Stylus 2 Plus (Android 8) phones, but it seems to fail when testing it on my Huawei P30 (Android 9).

I'm able to see all 3 devices as available from Android Studios' "Device File Explorer" tab, and browse the files in it, so I know that it is able to connect just fine.

Still, whenever I try to debug or run the app on my Huawei, the app is built, and as soon as it is going to start the install process, the phone disconnects and is immediately reconnected to the PC, resulting in a failed installation attempt.

All I can see from Android Studio is the following message:

Installation did not succeed.
The application could not be installed.
Installation failed due to: 'device 'ABCDEFGHIJKLM' not found'

I did have trouble getting the right drivers for the Huawei P30, but I believe that if I'm able to see the phone's files now, this should not be a driver issue anymore.

I've tried every phone configuration in the phone's developer options that I could find to no effect.

解决方案

TL;DR:

These two android tools' versions were outdated:

  • Android SDK Build-Tools

  • Android SDK Platform-Tools

Update all android tools to the latest version, and make sure no old ones linger around, and you should be good to go. =)


After I tried to upload the APK directly into my phone from Android Studios' "Device File Explorer" tab and it failed with the same behaviour, I knew something was wrong with the adb-server. So I proceeded to run the adb directly from the console with the following commands:

$ adb start-server
$ adb push abcdefg.apk 

The server started just fine, and resulted in the same behavior, but this showed me a new error/warning message that I was never shown in Android Studio:

adb server version (30) doesn't match this client (41); killing...

This was enough for me to find questions and blogpost like this one: How to resolve - "adb server version (32) doesn't match this client (36); killing…"

I guess this phone is very new compared to the old Android tools I have installed, so basically, all I had to do was to update these 2 tools (to the latest version) from the Android Studios's Android SDK configuration menu:

  • Android SDK Build-Tools

  • Android SDK Platform-Tools

Now, it is very important that you uninstall any old version of the tools that you may have lying around so that there is no chance that those get used (because it did happen to me during the process). You can check it by clicking the "Show package details" checkbox, and only check the latest version:

After this, kill adb from the Task Manager (if it was running), and restart Android Studio. This should make sure you are not using any old version.

这篇关于使用Android Studio通过USB连接时无法在手机上运行/调试应用(安装时会断开连接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆