从命令行创建大小合适的仿真器 [英] Create an emulator with a decent size from command line

查看:73
本文介绍了从命令行创建大小合适的仿真器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个装有Google API的ARM API 21仿真器.

I want to create an ARM API 21 emulator loaded with Google APIs.

这是我创建AVD的方法:

Here's how I create the 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

现在我用以下命令启动仿真器:

And now I start up the emulator with:

emulator -avd nexus4-emulator &

但是,这就是我得到的:屏幕尺寸很小(就有效像素而言):

However, this is what I get: a screen with tiny dimensions (in terms of effective pixels):

如何更改此配置,以使屏幕尺寸合适?

How can I change this config so that I have a properly sized screen?

顺便说一下,我正在使用它来构建APK并在Travis的计算机上运行测试,但是在我的计算机(Mac OS X)中是可复制的.

I'm using this to build APKs and run tests on a machine in Travis, by the way, but it's reproducible in my machine (Mac OS X).

推荐答案

更新:使用新的avdmanager修复分辨率


是创建模拟器的一个很好的示例使用新的 avdmanager

Update: fix resolution using the new avdmanager


This is a good sample to create an emulator with a decent size using the new 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 &

未解决问题参数进行了评论.

There is an open issue as commented here about the unsupported -s "768x1280" parameter.

如果您需要从命令行使用nexus 4样式的设备,则可以尝试以下操作:

If you need a nexus 4 style device from commandline, you can try this:

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更好.

Locally is better to use Android Studio.

用于CI构建的带有device选项的下一个配置解决了与屏幕尺寸有关的点击问题:

The next configuration with device option for CI builds solves click issues related to screen size:

  - 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 Studio,因为Nexus 4外观似乎仅放置在其中,并且SDK工具中包含的设备定义似乎不足以创建它.您需要定义额外的硬件选项.我在下面提供了一个解决方案.

Summary:


Local machine: the best option is to use Android Studio directly because the Nexus 4 skin seems placed only there and the device definition included in the SDK Tools seems not to be enough to create it; you need to define extra hardware options. I offer a work around below.

Travis-ci服务器:最好的选择是加快速度,以禁用音频和窗口并使用通用模拟器.如果您需要Nexus 4样式的模拟器,则可以尝试相同的解决方法,否则,请删除--device选项,并使用以下命令:

Travis-ci server: the best option is to speed up it disabling the audio and the window and to use a generic emulator. If you need a Nexus 4 style emulator you can try the same workaround, otherwise, remove the --device option and use commands like these:

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中定义的环境变量,否则,将使用右侧的默认值.最后一行显示有用的和相关的调试信息.

Note: on the left side are environment variables you can define in the .travis.yml, otherwise, the right side default values will be used. The last line prints useful and related debug information.

Nexus 4设备定义包含在

android-sdk-linux/tools/lib/devices.xml

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>

但是android-studio关联和使用的nexus_4外观仅在这里:

But the nexus_4 skin associated and used by android-studio is only here:

android-studio/plugins/android/lib/device-art-resources

android-studio/plugins/android/lib/device-art-resources

android-studio/plugins/android/lib/device-art-resources/device-art.xml

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,因此使用了SDK工具中包含的默认外观WVGA800:

You don't specify the --skin so the default skin WVGA800 included in the SDK tools is used:

此皮肤在hardware.ini文件中具有关联的硬件值:

This skin has associated hardware values in the hardware.ini file:

# 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并使用正确的皮肤.

This is not what you expect when you use the Nexus 4 device definition so I would use directly android-studio locally to create the avd and to use the correct skin.

如果您像以前一样使用命令行并尝试从android-studio中打开它,则会看到:

If you use the command line like you did and try to open it from android-studio, you'll see:

本地计算机解决方案

同时使用Android Studio;创建并启动模拟器.

Use Android Studio for both; create and start the emulator.

如果使用该命令创建它,并添加至少200MB的内部存储空间,则将解决屏幕尺寸问题,因为android-studio将使用正确的皮肤更新并修复avd.

If you create it using that command, adding a minimum of 200MB as internal storage, you'll solve the screen size issue because android-studio will update and fix the avd using the correct skin.

如果您要查找没有android-studio干预的命令,则将Nexus 4外观移至skins文件夹,向其添加了缺少属性的hardware.ini,最后执行了以下命令:

If you are looking for a command without android-studio intervention, I moved the Nexus 4 skin to the skins folder, added a hardware.ini with the missing properties to it and finally executed the next commands:

./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

这只是一个实验,我不推荐这样做,但是它似乎可以工作:

This is only an experiment, I don't recommend it, but it seems to work:

注意::我发现了有关avd名称的另一个问题,有时会替换为Nexus4_emulator.

Note: I found another issue about the avd name, replaced at some point, I would use Nexus4_emulator.

这不能解决Travis-ci案.您需要复制nexus_4外观或创建自定义外观并将其放置在您的项目或可访问的位置. (已更新:,我尝试了这个,它太慢了...)

This doesn't solve the Travis-ci case. You would need to copy the nexus_4 skin or create your custom skin and place it in your project or an accessible location. (Updated: I tried this, and it's so slow...)

但是您可能并不需要确切的Nexus 4外观,最好使用仿真器选项(例如-no-window-no-audio等)来加速它.

But you probably don't need an exact Nexus 4 skin, and it's better to use the emulator options like -no-window, -no-audio etc. to speed up it.

我通常使用-no-skin选项,但是我不知道hardware.ini关系,所以我可能会自定义模拟器,我需要对其进行更多研究.我发现在本地使用-no-skin选项时,屏幕尺寸不正确.请参阅下面的更新.

I normally used the -no-skin option, but I didn't know the hardware.ini relation, so I'll probably customise my emulator, I need investigate it more. I found that when using the -no-skin option locally, the screen size is not correct. See update below.

另一个选择是在启动模拟器时使用--skin 768x1280 -dynamic-skin. (更新:我在创建AVD时使用了此功能,但被忽略了)更多信息

Another option is to use --skin 768x1280 -dynamic-skin when starting the emulator. (updated: I used this when was creating the AVD but is ignored) Further information here:

此处

Alternative custom density from here

作为调整仿真器外观配置的替代方法,您可以 可以使用模拟器皮肤的默认密度并添加-dpi-device 启动AVD时仿真器命令行的选项.为了 例如:

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在此处评论

Update: tasomaniac commented here

-no-skin参数去除皮肤.这意味着模拟器的宽度为320x480像素,高度为320x,高度为320 大多数测试.默认皮肤为480x800,适合大多数情况 的情况.

-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.

-皮肤WXGA720可以如下使用,以使测试更加可信.这是默认情况下最好的模拟器配置.

--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

针对Android的320x480设备(具有320密度)表示该设备是 实际上是160x240.这样一来,屏幕上就无法容纳任何东西.与用户界面无关 模拟器中的测试通过,但与UI相关的Espresso测试将失败.

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也默认为仅-no-audio -no-window

Circle CI also defaults to only -no-audio -no-window

更新:下一个配置通过点击此处

Update: the next configuration solved an issue clicking views here

android.support.test.espresso.PerformException:执行错误 在视图上单击单击". 目标设备.

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 &

这篇关于从命令行创建大小合适的仿真器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆