Android Emulator not using webcam in Android Studi

2019-06-16 16:27发布

问题:

As the title suggests, I'm struggling to get the emulator use the webcam on the laptop. I have enabled the front and back camera to access the webcam. Whenever the emulator boots up it asks for webcam access, which I grant. However the webcam never works when I hit the camera app on the emulator. The camera app just crashes.

Here is an image enabling the cameras:

Based on other posts on StackOverflow, suggesting i add the line: hw.camera=yes. Below is the config file for the avd.

avd.ini.encoding=UTF-8
AvdId=Nexus_5_API_21_x86
abi.type=x86
avd.ini.displayname=Nexus 5 API 21 x86
disk.dataPartition.size=1G
hw.accelerometer=yes
hw.audioInput=yes
hw.battery=yes
hw.camera=yes
hw.camera.back=webcam0
hw.camera.front=webcam0
hw.cpu.arch=x86
hw.dPad=no
hw.device.hash2=MD5:2fa0e16c8cceb7d385183284107c0c88
hw.device.manufacturer=Google
hw.device.name=Nexus 5
hw.gps=yes
hw.gpu.enabled=yes
hw.keyboard=yes
hw.lcd.density=480
hw.mainKeys=no
hw.ramSize=1536
hw.sdCard=yes
hw.sensors.orientation=yes
hw.sensors.proximity=yes
hw.trackBall=no
image.sysdir.1=system-images\android-21\google_apis\x86\
runtime.network.latency=none
runtime.network.speed=full
runtime.scalefactor=auto
sdcard.path=C:\Users\Roberto\.android\avd\Nexus_5_API_21_x86.avd\sdcard.img
skin.dynamic=no
skin.name=nexus_5
skin.path=C:\Program Files\Android\Android Studio1\plugins\android\lib\device-art-resources\nexus_5
snapshot.present=no
tag.display=Google APIs
tag.id=google_apis
vm.heapSize=64

At this stage I'm not sure why this is not working. Any thoughts?

回答1:

I don't think you can set both front and back cameras to the same value. Please try to edit your config.ini file and change to this: hw.camera.back=none hw.camera.front=webcam0

Also, hw.camera=yes is not needed.

I hope that helps.



回答2:

I just had the same problem that the webcam would not start when I started the build from the "Run" tab on Android Studio 3.01. I then opened the AVD manager. In Edit mode for the Android 5.1 device and made sure to bump the SD card to 200M, both front/back set to webcam0 for the device I was emulating. Then closed the Edit mode and just double clicked on the device - and it worked!