Android emulator crashing due to access violation

I recently experienced a situation where Android Studio’s emulator crashed when starting an app that performed basic graphics operations.

Crash reason: EXCEPTION_ACCESS_VIOLATION_WRITE
Crash address: 0x66720000
Assertion: Unknown assertion type 0x00000000
Process uptime: 13 seconds

 

I started up Process Monitor to investigate the issue.

Tried recreating the situation, then stopped capturing events with: File -> Capture Events

Wanted to get an overview of the processes involved with: Tools -> Process Tree…

Right clicked studio64.exe and selected: Add process and children to Include filter

 

Noticed that emulator64-crash-service.exe left a memory dump under:

C:\Users\{user}\.android\breakpad\d16b5760-c4ac-4f06-a3ec-73aa74a70087.dmp

 

Examined the memory dump with WinDbg (x64).

Checked for details about the crash with:

!analyze -v

Part of the result:

FAULTING_IP:
ig9icd64!RegisterProcTableCallback+196cfb
000007fe`c5d9f71b f3410f7f48c0 movdqu xmmword ptr [r8-40h],xmm1

EXCEPTION_RECORD: ffffffffffffffff -- (.exr 0xffffffffffffffff)
ExceptionAddress: 000007fec5d9f71b (ig9icd64!RegisterProcTableCallback+0x0000000000196cfb)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 0000000000000001
Parameter[1]: 000000000ba50000
Attempt to write to address 000000000ba50000

STACK_TEXT:
... : ig9icd64!RegisterProcTableCallback+0x196cfb
... : ig9icd64!RegisterProcTableCallback+0x4a228e
... : ig9icd64!RegisterProcTableCallback+0x4a36b4
... : ig9icd64!RegisterProcTableCallback+0x4a828d
... : ig9icd64!RegisterProcTableCallback+0x4c52c7
... : ig9icd64!RegisterProcTableCallback+0x4c500f
... : ig9icd64!RegisterProcTableCallback+0x2ee1a2
... : lib64GLES_V2_translator!glReadPixels+0x297
... : lib64OpenglRender+0x364d
... : lib64OpenglRender+0x773b
... : lib64OpenglRender+0x11009
... : lib64OpenglRender!initLibrary+0x52e3
... : lib64OpenglRender!initLibrary+0xc4e2c
... : lib64OpenglRender!initLibrary+0x4c7a4
... : kernel32!BaseThreadInitThunk+0xd
... : ntdll!RtlUserThreadStart+0x1d

 

This indicated that the problem was related to graphics drivers and/or settings.

I did not have important data on the Android emulator, so I made it boot again by removing all data (including the auto-starting app, which crashed the emulator).

Did this in Android Virtual Device manager with the Wipe Data option.

 

When the emulator could start again I started looking for additional graphics settings.

Found some under Extended controls -> Settings section -> Advanced tab.

The default setting for OpenGL ES renderer (Autodetect based on host) seemed problematic on this system.

I experimented with the settings and discovered that SwiftShader worked well. Running graphics rendering apps with this setting no longer crashed the emulator.

The problem occurred on a desktop system with an Intel Skylake CPU (Core i7-6700) running Windows 7 using Intel HD Graphics 530 with driver version 21.20.16.4860.

Conclusion

If Android Studio’s emulator crashes when running graphics rendering apps, it may help changing the OpenGL ES renderer setting.

Android emulator hanging with black screen

I recently experienced a situation where Android Studio’s x86 emulator would not start.

It just showed a black screen with no apparent progress.

 

To investigate I connected Android Device Monitor to the emulator.

LogCat showed a lot of messages and they seemed to repeat over and over.

 

I decided to pause the emulator to examine the log.

Found and followed Christoper Orr’s advice here:

telnet localhost 5554
avd stop

 

Checked the LogCat messages and noticed this section:

I/ServiceManager(16997): Waiting for service SurfaceFlinger...
I/SurfaceFlinger(17248): SurfaceFlinger is starting
I/SurfaceFlinger(17248): SurfaceFlinger's main thread ready to run. Initializing graphics H/W...
D/libEGL(17248): Emulator has vendor provided software renderer, qemu.gles is set to 2.
D/libEGL(17248): loaded /vendor/lib/egl/libEGL_swiftshader.so
D/libEGL(17248): loaded /vendor/lib/egl/libGLESv1_CM_swiftshader.so
D/libEGL(17248): loaded /vendor/lib/egl/libGLESv2_swiftshader.so
D/gralloc_ranchu(17248): Emulator without host-side GPU emulation detected.
E/gralloc_ranchu(17248): Could not find software fallback module!?
E/gralloc_ranchu(17248): [ 07-04 12:54:38.858 17248:17248 E/ ]
E/gralloc_ranchu(17248): connect: failed with fd -1 errno 22
E/gralloc_ranchu(17248): [ 07-04 12:54:38.858 17248:17248 E/ ]
E/gralloc_ranchu(17248): Failed to connect to host (QemuPipeStream)!!!
E/gralloc_ranchu(17248): gralloc: Failed to get host connection
E/SurfaceFlinger(17248): hwcomposer module not found
E/SurfaceFlinger(17248): ERROR: failed to open framebuffer (I/O error), aborting
A/libc(17248): Fatal signal 6 (SIGABRT), code -6 in tid 17248 (surfaceflinger)
A/libc(17248): [ 07-04 12:54:38.858 1319: 1319 W/ ]
A/libc(17248): debuggerd: handling request: pid=17248 uid=1000 gid=1003 tid=17248
I/ServiceManager(17212): Waiting for service SurfaceFlinger...
I/ServiceManager(17212): [ 07-04 12:54:38.860 17256:17256 E/ ]
I/ServiceManager(17212): debuggerd: Unable to connect to activity manager (connect failed: Connection refused)

 

Decided to check the emulator configuration.

Noticed that the emulator was configured to use software graphics.

Changed this to hardware graphics, started the emulator again and noticed that it started normally. The workaround solved the problem.

 

Conclusion

If the Android Studio emulator hangs with a black screen, try checking the LogCat messages and try switching graphics mode.

Android Studio build failing due to Gradle NullPointerException

I recently experienced problems with Android Studio, where it would no longer clean or rebuild a particular project.

 

The Gradle Console showed this message:

FAILURE: Build failed with an exception.

* What went wrong:
java.lang.NullPointerException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

 

Tried selecting: File menu -> Invalidate Caches / Restart…

Unfortunately this had no effect.

 

Looked for more details by building from a commandline with the suggested options:

gradlew build --stacktrace --debug > build_debug_log.txt 2> build_debug_error.txt

 

(It was neccessary to log standard output and error output separately, because otherwise they would get mixed up)

However the Gradle output still didn’t explain clearly why the build process was failing.

 

Found a suggestion to delete the .gradle folder in the project folder here:

http://stackoverflow.com/questions/39183674/java-lang-nullpointerexception-no-error-message

 

I closed the Android Studio project, moved the .gradle folder outside of the project folder and reopened the Android Studio project.

This solved the problem!

It was now possible to clean and rebuild the project again.

Conclusion

If Android Studio refuses to build due to NullPointerException from Gradle, try removing or moving the .gradle folder from the affected project.

USB driver problem preventing access to Samsung Android devices

I recently experienced problems connecting to Samsung Android devices with Android Studio from my work computer.

No Connected Devices were available.

 

I checked Device Manager and noticed a warning for: SAMSUNG Mobile USB Composite Device

 

Checked Properties and noticed the Device status:

Windows cannot load the device driver for this hardware. The driver may be corrupted or missing. (Code 39)

 

I checked driver details and noticed that the driver was unexpectedly: usbpcap.sys.

(The problem occured after installing Wireshark and USBPcap…)

 

I decided to uninstall USBPcap. However this didn’t solve the problem, but changed the message for driver details to:

No driver files are required or have been loaded for this device.

 

Fixed the problem this way:

1. Clicked: Update Driver…

 

2. Clicked: Browse my computer for driver software

 

3. Clicked: Let me pick from a list of device drivers on my computer

 

4. Selected: SAMSUNG Mobile USB Composite Device Version: 2.12.4.0 [24-08-2016]

 

5. Clicked: Next

6. Noticed the message: Windows has successfully updated your driver software

 

7. Checked driver details, which now had the desired driver file:

C:\Windows\system32\DRIVERS\ssudbus.sys

 

This fixed the problem. It was again possible to connect to Samsung Android devices from Android Studio.