我想创建一个装有 Google API 的 ARM API 21 模拟器。
这是我创建 AVD 的方法:
ANDROID_ABI=google_apis/armeabi-v7a
EMULATOR_VERSION=21
avd --force -n nexus4-emulator -t "Google Inc.:Google APIs:"$EMULATOR_VERSION --abi $ANDROID_ABI --device "Nexus 4" -c 128M
现在我启动模拟器:
emulator -avd nexus4-emulator &
但是,这就是我得到的:尺寸很小的屏幕(就有效像素而言):
如何更改此配置以便我拥有合适大小的屏幕?
顺便说一下,我正在使用它来构建 APK 并在 Travis 的机器上运行测试,但它可以在我的机器(Mac OS X)中重现。
最佳答案
更新:使用新的 avdmanager 修复分辨率
This是使用新 avdmanager 创建大小合适的仿真器的好示例。 :
- $ANDROID_HOME/tools/bin/avdmanager create avd --force --name test --package 'system-images;android-22;default;armeabi-v7a' --abi armeabi-v7a --device 'Nexus 4' --sdcard 128M
- $ANDROID_HOME/emulator/emulator -avd test -skin 768x1280 -no-audio -no-window &
有一个open issue如 commented here关于不受支持的
-s "768x1280"
范围。上一个答案
如果你需要一个来自命令行的 nexus 4 风格的设备,你可以试试这个:
android create avd --force -n nexus4-emulator -t "Google Inc.:Google APIs:"$EMULATOR_VERSION --abi $ANDROID_ABI -s "768x1280" --device "Nexus 4" -c 128M
在本地使用 Android Studio 更好。
下一个配置与
device
CI 构建选项解决了与屏幕尺寸相关的点击问题: - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI --device 'Nexus 4' --sdcard 128M
- emulator -avd test -no-window -skin 768x1280 &
摘要:
native :最好的选择是直接使用 Android Studio,因为 Nexus 4 皮肤似乎只放在那里,而 SDK 工具中包含的设备定义似乎不足以创建它;您需要定义额外的硬件选项。我在下面提供了一个解决方法。
Travis-ci 服务器:最好的选择是加速它禁用音频和窗口并使用通用模拟器。如果您需要 Nexus 4 风格的模拟器,您可以尝试相同的解决方法,否则,请删除
--device
选项并使用如下命令:android create avd -f \
-n "${AVD_NAME:-default_emulator}" \
-t "${AVD_TARGET:-Google Inc.:Google APIs:21}" \
-b "${AVD_ABI:-armeabi-v7a}" \
-g "${AVD_TAG:-google_apis}" \
-c "${AVD_SDCARD:-128M}"
emulator -avd "${AVD_NAME:-default_emulator}" \
-no-audio \
-no-window \
-debug "${AVD_DEBUG:-avd_config}" &
注:左侧是您可以在 .travis.yml 中定义的环境变量,否则将使用右侧的默认值。最后一行打印有用的和相关的调试信息。
本地配置
Nexus 4
设备定义包含在android-sdk-linux/tools/lib/devices.xml
<d:device>
<d:name>Nexus 4</d:name>
<d:manufacturer>Google</d:manufacturer>
<d:hardware>
<d:screen>
<d:screen-size>normal</d:screen-size>
<d:diagonal-length>4.7</d:diagonal-length>
<d:pixel-density>xhdpi</d:pixel-density>
<d:screen-ratio>notlong</d:screen-ratio>
<d:dimensions>
<d:x-dimension>768</d:x-dimension>
<d:y-dimension>1280</d:y-dimension>
</d:dimensions>
<d:xdpi>320</d:xdpi>
<d:ydpi>320</d:ydpi>
<d:touch>
<d:multitouch>jazz-hands</d:multitouch>
<d:mechanism>finger</d:mechanism>
<d:screen-type>capacitive</d:screen-type>
</d:touch>
</d:screen>
<d:networking>
Wifi
Bluetooth
NFC
</d:networking>
<d:sensors>
Accelerometer
Barometer
Compass
GPS
Gyroscope
LightSensor
ProximitySensor
</d:sensors>
<d:mic>true</d:mic>
<d:camera>
<d:location>back</d:location>
<d:autofocus>true</d:autofocus>
<d:flash>true</d:flash>
</d:camera>
<d:camera>
<d:location>front</d:location>
<d:autofocus>false</d:autofocus>
<d:flash>false</d:flash>
</d:camera>
<d:keyboard>nokeys</d:keyboard>
<d:nav>nonav</d:nav>
<d:ram unit="KiB">1953125</d:ram>
<d:buttons>soft</d:buttons>
<d:internal-storage unit="KiB">7811891</d:internal-storage>
<d:removable-storage unit="MiB"></d:removable-storage>
<d:cpu>Qualcomm Snapdragon S4 Pro</d:cpu>
<d:gpu>Adreno 320</d:gpu>
<d:abi>
armeabi-v7a
armeabi
</d:abi>
<d:dock></d:dock>
<d:power-type>battery</d:power-type>
</d:hardware>
<d:software>
<d:api-level>16</d:api-level>
<d:live-wallpaper-support>true</d:live-wallpaper-support>
<d:bluetooth-profiles></d:bluetooth-profiles>
<d:gl-version>2.0</d:gl-version>
<d:gl-extensions>GL_EXT_debug_marker GL_AMD_compressed_ATC_texture
GL_AMD_performance_monitor GL_AMD_program_binary_Z400 GL_EXT_robustness
GL_EXT_texture_format_BGRA8888 GL_EXT_texture_type_2_10_10_10_REV GL_NV_fence
GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_depth24
GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_element_index_uint
GL_OES_fbo_render_mipmap GL_OES_fragment_precision_high GL_OES_get_program_binary
GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives
GL_OES_texture_3D GL_OES_texture_float GL_OES_texture_half_float
GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_vertex_half_float
GL_OES_vertex_type_10_10_10_2 GL_OES_vertex_array_object GL_QCOM_alpha_test
GL_QCOM_binning_control GL_QCOM_driver_control GL_QCOM_perfmon_global_mode
GL_QCOM_extended_get GL_QCOM_extended_get2 GL_QCOM_tiled_rendering
GL_QCOM_writeonly_rendering GL_EXT_sRGB
</d:gl-extensions>
<d:status-bar>true</d:status-bar>
</d:software>
<d:state name="Portrait" default="true">
<d:description>The phone in portrait view</d:description>
<d:screen-orientation>port</d:screen-orientation>
<d:keyboard-state>keyssoft</d:keyboard-state>
<d:nav-state>nonav</d:nav-state>
</d:state>
<d:state name="Landscape">
<d:description>The phone in landscape view</d:description>
<d:screen-orientation>land</d:screen-orientation>
<d:keyboard-state>keyssoft</d:keyboard-state>
<d:nav-state>nonav</d:nav-state>
</d:state>
</d:device>
但是
nexus_4
android-studio 关联和使用的皮肤仅在此处:android-studio/plugins/android/lib/device-art-resources
android-studio/plugins/android/lib/device-art-resources/device-art.xml
<device id="nexus_4" name="Nexus 4">
<orientation name="port" size="958,1678" screenPos="94,187" screenSize="768,1280" shadow="port_shadow.png" back="port_back.png" lights="port_fore.png"/>
<orientation name="land" size="1799,885" screenPos="257,45" screenSize="1280,768" shadow="land_shadow.png" back="land_back.png" lights="land_fore.png"/>
</device>
您没有指定
--skin
所以默认皮肤WVGA800
包含在 SDK 工具中的使用:此皮肤在
hardware.ini
中有关联的硬件值。文件:# skin-specific hardware values
hw.lcd.density=240
vm.heapSize=48
hw.ramSize=512
和
layout
文件包括下一行:...
device {
display {
width 480
height 800
...
当您使用 Nexus 4 设备定义时,这不是您所期望的,因此我将直接在本地使用 android-studio 来创建 avd 并使用正确的皮肤。
如果您像以前一样使用命令行并尝试从 android-studio 打开它,您将看到:
本地机解决方案
两者都使用 Android Studio;创建并启动模拟器。
如果您使用该命令创建它,添加至少 200MB 作为内部存储空间,您将解决屏幕尺寸问题,因为 android-studio 将使用正确的皮肤更新和修复 avd。
如果您正在寻找没有 android-studio 干预的命令,我将 Nexus 4 皮肤移动到 skins 文件夹,添加了一个具有缺少属性的 hardware.ini,最后执行了下一个命令:
./android create avd -f \
-n "${AVD_NAME:-nexus4_emulator}" \
-t "${AVD_TARGET:-Google Inc.:Google APIs:21}" \
-b "${AVD_ABI:-armeabi-v7a}" \
-g "${AVD_TAG:-google_apis}" \
-s "${AVD_SKIN:-nexus_4}" \
-d "${AVD_DEVICE:-Nexus 4}" \
-c "${AVD_SDCARD:-128M}"
./emulator -avd nexus4_emulator &
hardware.ini
内容:# skin-specific values
AvdId=nexus4_emulator
avd.ini.displayname=nexus4 emulator
disk.dataPartition.size=200M
hw.camera.back=none
hw.camera.front=none
hw.gpu.enabled=yes
hw.lcd.density=320
hw.ramSize=1024
runtime.network.latency=none
runtime.network.speed=full
runtime.scalefactor=auto
skin.dynamic=yes
snapshot.present=no
vm.heapSize=64
这只是一个实验,我不推荐它,但它似乎有效:
注:我发现了另一个关于 avd 名称的问题,在某个时候被替换,我会使用
Nexus4_emulator
.CI 配置
这并不能解决 Travis-ci 的问题。您需要复制
nexus_4
皮肤或create your custom skin并将其放置在您的项目或可访问的位置。 ( 更新: 我试过这个,它太慢了......)但是您可能不需要精确的 Nexus 4 皮肤,最好使用像
-no-window
这样的模拟器选项。 , -no-audio
等等来加速它。我通常使用
-no-skin
选项,但我不知道 hardware.ini 的关系,所以我可能会自定义我的模拟器,我需要更多地研究它。我发现在使用 -no-skin
时本地选项,屏幕尺寸不正确。请参阅下面的更新。另一种选择是使用
--skin 768x1280 -dynamic-skin
当启动模拟器。 (更新:我在创建 AVD 时使用了这个但被忽略了)更多信息 here :来自 here 的替代自定义密度
As an alternative to adjusting the emulator skin configuration, you can use the emulator skin's default density and add the -dpi-device option to the emulator command line when starting the AVD. For example:
emulator -avd WVGA800 -scale 96dpi -dpi-device 160
更新: tasomaniac 评论 here
-no-skin parameter removes the skin. This means that the emulator will be 320x480 pixel widthxheight and 320 density which messes up with most of the tests. The default skin is 480x800 which is fine for most of the cases.
--skin WXGA720 can be used like below to make tests more trusted. This is the best emulator config that is found by default.
- echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a --skin WXGA720
320x480 device with 320 density for Android means that the device is actually 160x240. With this nothing fits in the screen. Non UI related tests in the emulator passes but UI related Espresso tests will fail.
Circle CI also defaults to only -no-audio -no-window
更新:下一个配置解决了点击 View 的问题 here
android.support.test.espresso.PerformException: Error performing 'single click' on view 'Animations or transitions are enabled on the target device.
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI --device 'Nexus 4' --sdcard 128M
- emulator -avd test -no-window -skin 768x1280 &
关于android - 从命令行创建一个大小合适的模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32914660/