如何使用 Android Studio 在真实设备中测试 Android 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21947834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:21:28  来源:igfitidea点击:

How to test android apps in a real device with Android Studio?

androidandroid-studio

提问by Miguel ángel

I started to develop in android with Android Studio IDE, I tested my apps on the emulatorand works fine, but when I tried to test the apps directly in my device doesn't recognize it and the console shows next message:

我开始在 android 中开发Android Studio IDE,我在 android 上测试了我的应用程序emulator并且工作正常,但是当我尝试直接在我的设备中测试应用程序时无法识别它并且控制台显示下一条消息:

Waiting for device. USB device not found

等待设备。未找到 USB 设备

  • I configured "USB Device" in Run>Edit Configurations...> in tab "General", menu "Target Device"
  • I enabled the "Debug option" in my device
  • Plug/Unplug USB
  • 我在“运行”>“编辑配置...”中配置了“USB 设备”,在“常规”选项卡,菜单“目标设备”中
  • 我在我的设备中启用了“调试选项”
  • 插入/拔出 USB

采纳答案by Miguel ángel

I can run on my device at last, just I enabled the "USB debugging"and "Allow mock location"options from the Debug Menu of my device.

我终于可以在我的设备上运行了,只是我从设备的调试菜单中启用了“USB 调试”“允许模拟位置”选项。

回答by Let's help

  • First we have to enable the USB debugging mode. for that go to Settings-> Developer Options->USB debuggingin your phone checked it and allow it.
  • After it open android studio, click on SDK manager , check mark the Google USB Driverand hit install package.
  • After Installing Google USB Driver, close SDK Manager window, Connect your phone or tablet through USB cable to your laptop or PC.
  • Now click on My Computer (Windows 7) (or) This PC(Windows 8.1).Select Manage.
  • Select Device Manager –> Portable Devices –> Your Device Name
  • Right Click on Your Device Nameand Select Browse My Computer For Driver Software.
  • Point it to C:\Users\YourUserName\AppData\Local\Android\sdk\extras\google\usb_driver. Hit Next and Finish.
  • Now Hit Run Button after selecting Your Project in Project Explorer in Android studio. Choose your device and press OK.
  • 首先我们必须启用USB调试模式。为此,请转到“设置”->“开发人员选项”->“ 手机中的USB 调试”检查它并允许它。
  • 打开android studio后,点击SDK manager,勾选Google USB Driver并点击安装包
  • 安装 Google USB Driver 后,关闭 SDK Manager 窗口,通过 USB 线将您的手机或平板电脑连接到您的笔记本电脑或 PC。
  • 现在单击我的电脑(Windows 7)(或)这台电脑(Windows 8.1)。选择管理。
  • 选择设备管理器 –> 便携式设备 –> 您的设备名称
  • 右键单击您的设备名称,然后选择浏览我的计算机以查找驱动程序软件。
  • 将其指向 C:\Users\YourUserName\AppData\Local\Android\sdk\extras\google\usb_driver。点击下一步并完成。
  • 在 Android Studio 的项目资源管理器中选择您的项目后,现在点击运行按钮。选择您的设备,然后按 OK。

回答by Karma Contributor

I have a Nexus 4 and own a Thinkpad L430 Windows 8.1

我有一台 Nexus 4 并拥有一台 Thinkpad L430 Windows 8.1

My errors: "Waiting for device. USB device not found"

我的错误:“正在等待设备。未找到 USB 设备”

I went to: Device Manager > View > Drop to "Acer Device" > Right click on Acer Composite ADB Interface > Update it

我去了:设备管理器>查看>放到“Acer设备”>右键单击Acer Composite ADB接口>更新它

Afterward, Reboot/Restart your computer. Once it turned on Plug Your USB Device onto the computer.

之后,重新启动/重新启动您的计算机。打开后,将您的 USB 设备插入计算机。

Go to: Setting > Enable "Developer options" > Check the "USB debugging" option > Check "Allow mock locations" > Check "Verify apps over USB".

转到:设置>启用“开发人员选项”>选中“USB调试”选项>选中“允许模拟位置”>选中“通过USB验证应用程序”。

Swipe down from the drop down menu of your phone where it Shows the USB Connection Icon. Tap on USB Computer Connection > Select the Check box "Camera (PTP)"

从显示 USB 连接图标的手机下拉菜单中向下滑动。点击 USB 计算机连接 > 选择复选框“相机(PTP)”

Run your Android Studio App and it should work

运行你的 Android Studio 应用程序,它应该可以工作

回答by Mr. Stark

To test an android apps in a real device with Android Studio, You must keep two things in mind

要使用 Android Studio 在真实设备中测试 android 应用程序,您必须牢记两件事

  1. You should enable USB debuggingoption on your android phone.
  2. You must have driverinstalled on your computer.
  1. 您应该在 Android 手机上启用USB 调试选项。
  2. 您必须在计算机上安装驱动程序。

Now , let me tell you how you can enable USB debuggingon your android phone:

现在,让我告诉你如何在你的安卓手机上启用 USB 调试

  1. Go to Settingson your android phone
  2. Scroll down to the bottom and click on About phone
  3. On this menu also scroll down to the bottom, you should see something Build number
  4. Click on Build number 7 times
  5. Now your Developer Option enables, once you done click on back button and you should see a new option on your android screen i.e. Developer Options
  6. Click On Developer Options
  7. Scroll down until you see USB Debugging
  8. Go ahead and click the check box next to the USB debugging
  9. Now your USB Debuggingoption enables.
  10. Connect your android device to your computer with the help of USB connector.
  1. 转到Android 手机上的“设置”
  2. 向下滚动到底部,然后单击关于手机
  3. 在此菜单上也向下滚动到底部,您应该会看到内部版本号
  4. 单击内部版本号 7 次
  5. 现在你的开发者选项启用,一旦你完成点击后退按钮,你应该在你的安卓屏幕上看到一个新选项,即开发者选项
  6. 点击开发者选项
  7. 向下滚动,直到您看到USB 调试
  8. 继续并单击 USB 调试旁边的复选框
  9. 现在您的USB 调试选项已启用。
  10. 借助 USB 连接器将您的 android 设备连接到您的计算机。

Now let me tell you how you can download the driver on your Windows PC:

现在让我告诉您如何在 Windows PC 上下载驱动程序:

  1. Your windows machine need a software called driverto communicate with your phone.
  2. Go To OEM USB Driver Websiteto install your appropriate driver
  3. Scroll down and select the driver appropriate for your device. Check the screen shoot
  4. Once you download it , you have to unzip your file
  5. After Installing Google USB Driver, close SDK Manager window, Connect your phone or tablet through USB cable to your laptop or PC.
  6. Now click on My Computer (Windows 7) (or) This PC(Windows 8.1).Select Manage.
  7. Select Device Manager –> Portable Devices –> Your Device Name
  8. Right Click on Your Device Name and Select Browse My Computer For Driver Software.
  9. Point it to C:\Users\YourUserName\AppData\Local\Android\sdk\extras\google\usb_driver. Hit Next and Finish.
  10. Now Hit Run Button after selecting Your Project in Project Explorer in Android studio. Choose your device and press OK.
  1. 您的 Windows 机器需要一个名为驱动程序的软件来与您的手机进行通信。
  2. 转至OEM USB 驱动程序网站以安装合适的驱动程序
  3. 向下滚动并选择适合您设备的驱动程序。 检查屏幕截图
  4. 下载后,您必须解压缩文件
  5. 安装 Google USB Driver 后,关闭 SDK Manager 窗口,通过 USB 线将您的手机或平板电脑连接到您的笔记本电脑或 PC。
  6. 现在单击我的电脑(Windows 7)(或)这台电脑(Windows 8.1)。选择管理。
  7. 选择设备管理器 –> 便携式设备 –> 您的设备名称
  8. 右键单击您的设备名称,然后选择浏览我的计算机以查找驱动程序软件。
  9. 将其指向 C:\Users\YourUserName\AppData\Local\Android\sdk\extras\google\usb_driver。点击下一步并完成。
  10. 在 Android Studio 的项目资源管理器中选择您的项目后,现在点击运行按钮。选择您的设备,然后按 OK。

回答by Zahoor Ahmad

For Android 7, Galaxy S6 Edge:

对于 Android 7、Galaxy S6 Edge:

  1. Settings > Developer Options > Turn the switch ON > Debugging Mode (Turn On)
  1. 设置 > 开发者选项 > 打开开关 > 调试模式(打开)

If Developer Optionsis not available then

如果开发者选项不可用,则

  1. Settings > About Device > Software Info > Build number (Tap It 7 time)
  1. 设置 > 关于设备 > 软件信息 > 版本号(点击 7 次)

Now perform step 1. Now it should work, if its still not working then perform thesesteps. It worked for me.

现在执行第 1 步。现在它应该可以工作了,如果它仍然无法工作,则执行这些步骤。它对我有用。

回答by Mohammad

I tried @Mr. Stark answer. It didn't work. It failed to install the drive. I have Samsung S8 plus. I enabled the debugging mode on device then installed Android USB Driver for Windows from Samsung site, it works.

我试过@Mr。斯塔克回答。它没有用。驱动安装失败。我有三星 S8 Plus。我在设备上启用了调试模式,然后从三星网站安装了适用于 Windows 的 Android USB 驱动程序,它工作正常。

回答by cinobili19

if you are using IOS react native platformand want to debugging real android device you can use following code:

如果您使用 IOS React Native 平台并想调试真正的 android 设备,您可以使用以下代码:

adb reverse tcp:8081 tcp:8081
npm start -- --reset-cache
react-native run-android

回答by Pratik Mohanrao Gondil

You have to Download the driver for your Device just go to device manager-->> your device-->update driver-->choose the usb driver path from sdk extras folder and click next. You can get the correct driver and you can run on real device

您必须为您的设备下载驱动程序,只需转到设备管理器-->>您的设备-->更新驱动程序-->从 sdk extras 文件夹中选择 USB 驱动程序路径,然后单击下一步。您可以获得正确的驱动程序,您可以在真机上运行

回答by oyenigun

If USB Debugging Mode is enabled and does not work, you should install your device driver.

如果 USB 调试模式已启用且不起作用,则应安装设备驱动程序。

For Nexus Devices;

对于 Nexus 设备;

  • Install Google USB Drivers on SDK Tools.
  • Go to Control Panel > Device Manager and check drivers status. (Probably you can see warning icon on ADB Interface Driver.) Select ADB Interface driver and click update. Choose "Browse my computer for driver software" and set folder path like "D:\Users\userName\AppData\Local\Android\sdk".
  • 在 SDK 工具上安装 Google USB 驱动程序。
  • 转到控制面板 > 设备管理器并检查驱动程序状态。(您可能会在 ADB 接口驱动程序上看到警告图标。)选择 ADB 接口驱动程序并单击更新。选择“浏览我的计算机以查找驱动程序软件”并设置文件夹路径,如“D:\Users\userName\AppData\Local\Android\sdk”。

For Another Devices;

对于其他设备;

  • If you install the model's driver, it may work. For ex: Samsung Kies, LG PC Suite.
  • 如果您安装模型的驱动程序,它可能会工作。例如:三星凯斯、LG PC 套件。

Hope it helps!

希望能帮助到你!