CentOS7下Jenkins-AndroidEmulator插件创建AVD失败求助
Troubleshooting Jenkins-AndroidEmulator + Maven Headless Emulator Issue on CentOS 7
Hey there, let's break down why your Appium script works smoothly on Windows with Genymotion but hits snags on CentOS 7 using Jenkins' Android Emulator plugin. I've dealt with similar headaches before, so here are the key areas to check and fix:
1. Headless Mode & Graphics Context Conflicts
Even though your CentOS server has a GUI, Jenkins might not be running with the right graphical context to launch the emulator properly:
- First, check if the
DISPLAYenvironment variable is set for the Jenkins user. Add this echo command to your build steps to verify:
If it returns empty, manually set it before starting the emulator (adjustecho $DISPLAY:0to match your server's display number if needed):export DISPLAY=:0 - Double-check that the Jenkins Android Emulator plugin is passing the correct headless flags. Look through your build logs for the emulator startup command—it should include either
-no-windowor-headless(depending on your emulator version). If not, tweak the plugin's configuration to add these parameters.
2. AVD & Virtualization Compatibility
Your AVD might not be optimized for CentOS's server environment:
- Verify KVM support: Android emulators rely on KVM for performance, and it's often disabled by default on servers. Run this command to check if your CPU supports virtualization:
If the output isegrep -c '(vmx|svm)' /proc/cpuinfo0, enable virtualization in your server's BIOS, then load the KVM module:
Add these modules to# For Intel CPUs modprobe kvm-intel # For AMD CPUs modprobe kvm-amd/etc/modules-load.d/kvm.confto make the change persistent on reboot. - Check the AVD system image: Make sure you downloaded the Linux version of the android-26 system image (not the Windows one). List your AVDs to confirm:
Ensure the image path points to a Linux-compatible file under your Android SDK'savdmanager list avdsystem-imagesdirectory.
3. Jenkins Plugin & Maven Integration
The plugin might not be properly prepping the emulator before your tests run:
- Double-check plugin settings: Confirm the plugin is using the correct Android SDK path, and the AVD name matches exactly what you created—typos here are a super common culprit.
- Wait for the emulator to fully boot: Emulators take time to finish initializing; don't jump straight to running tests. Add these steps to your build to wait for the device to be ready:
adb wait-for-device # Wait for the system to complete bootup until adb shell getprop sys.boot_completed | grep -m 1 1; do sleep 1; done - Update Appium capabilities: Tweak your Maven-configured Appium caps to fit the headless emulator. For example:
capabilities.setCapability("avd", "YourExactAVDName"); capabilities.setCapability("avdLaunchTimeout", 120000); // Extend timeout if needed capabilities.setCapability("noReset", true);
4. Permissions & Missing Dependencies
CentOS often lacks some libraries needed for the emulator, and permission issues can block AVD access:
- Fix AVD directory permissions: Ensure the Jenkins user has read/write access to
~/.android/avd/and your Android SDK directory. If Jenkins runs as root (not ideal), adjust ownership with:chown -R jenkins:jenkins ~/.android/ - Install missing libraries: Run this command to check for missing dependencies in the emulator binary:
Install any missing packages with yum—common ones include:ldd $ANDROID_HOME/emulator/emulatoryum install mesa-libGL-devel libstdc++.i686
内容的提问来源于stack exchange,提问作者Suresh Sharma
相关产品推荐
相关产品推荐

