Problem
If the code is working fine on Android real device but not working on Android Emulator. For example, getting the below error:
E/emuglGLESv2_enc( 4288): device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glGetUniformLocation:2206 GL error 0x502
Solution
Downgrade the Android Emulator version to 34.2.13, which is the latest stable version that don’t throw the error.
How to manually install a specified version of Android Emulator
To manually install a specified version of Android Emulator on Android Studio, you need to paste the desired emulator package contents into your SDK installation directory, and change the emulator version specified in the package.xml file. Specifically, follow these steps:
- Locate your SDK installation directory. The default location of this directory varies by platform:
- On Windows, it’s the
%LocalAppData%\Android\Sdkdirectory. This normally expands toC:\Users\<username>\AppData\Local\Android\Sdk, although it might vary based on your system. - On macOS, it’s the
$HOME/Library/Android/sdk directory. - On Linux, it’s the
$HOME/Android/Sdk directory.
You can also check where your SDK installation directory is by opening Android Studio and clicking Android Studio > Preferences > Appearances & Behavior > System Settings > Android SDK. The Android SDK Location file path is your SDK installation directory location.
If you’re using macOS and browsing using Finder, the Library folder might not be visible by default. To navigate there, open Finder and click Go > Go to Folder and search for “Library.”
- Rename the existing
emulatordirectory in the SDK installation directory, because you’ll unzip the newly downloadedemulatordirectory here in the next step. For example, call itemulator_original. - Download the emulator archive that you want to use from here
- Unzip the emulator zip file you downloaded, and then move the contents into the SDK installation directory.
- On macOS: After unzipping the emulator zip file, clear the quarantine attribute on the emulator package by running:
xattr -dr com.apple.quarantine emulator/
This should reduce messages about whether the package should be checked or blocked. - Paste the
package.xmlfile from theemulator_originaldirectory into the newemulatordirectory.
Change the emulator version specified in thepackage.xmlfile to the version you have downloaded and want to use. To do this, scroll to the bottom of the package.xml file and find the text that looks like:<revision><major>31</major><minor>1</minor><micro>4</micro></revision>
This is where you should specify the emulator version you downloaded and want to install.