繁体   English   中英

从源代码构建 Android 后运行模拟器

[英]Running emulator after building Android from source

我能够将最新的 android 源代码下载到 32 位 Ubuntu 虚拟机(主机:Windows 7 64 位)中。 构建完成,没有任何错误。

然后我尝试按照这些说明进行操作,其中提到我应该在源代码的根目录上运行模拟器。 但是,当我尝试这样做时,我收到一条错误消息,指出找不到此命令。

所以我去了文件夹out/host/linux-x86/bin ,我发现emulator*有几个文件:

  • emulator
  • emulator-arm
  • emulator_renderer
  • emulator-ui
  • emulator-x86

当我在这里输入emulatoremulator-x86 ,它也不起作用。 这是我得到的错误:

xxxx/out/host/linux-x86/bin$ ./emulator-x86
emulator: ERROR: You did not specify a virtual device name, and the system
directory could not be found.

If you are an Android SDK user, please use '@<name>' or '-avd <name>'
to start a given virtual device (see -help-avd for details).

Otherwise, follow the instructions in -help-disk-images to start the emulator

因此,当我运行./emulator-x86 -help-disk-images ,我看到以下内容:

If you are building from the Android build system, you should
have ANDROID_PRODUCT_OUT defined in your environment, and the
emulator shall be able to pick-up the right image files automatically.
See -help-build-images for more details.

我自己构建了这个,所以我认为ANDROID_PRODUCT_OUT是在我的环境变量中设置的,但我没有看到它。 所以我认为我应该运行一些其他的 shell 脚本来获得该设置。

我查看了img文件,我在out/target/product/generic位置看到了几个:

  • ramdisk.img
  • system.img
  • userdata.img

任何人都可以对此有所了解并帮助我下一步该怎么做? 我是 Android 新手,对此做了一些研究,但找不到任何类似的问题。

我不知道您为哪个产品进行构建,但要运行模拟器,您可以使用以下命令:

out/host/linux-x86/bin/emulator -sysdir out/target/product/generic/ -system out/target/product/generic/system.img -ramdisk out/target/product/generic/ramdisk.img -data out /target/product/generic/userdata.img -kernel prebuilt/android-arm/kernel/kernel-qemu -sdcard sdcard.img -skindir sdk/emulator/skins -skin WVGA800 -scale 0.7 -memory 512 -partition-size 1024

只需将其复制到 Android 源文件夹根目录中的 .sh 文件中并运行此文件即可。 或者你可以直接运行它,但你首先应该 chdir 到你的 Android 源文件夹根目录。

并且不要忘记使用命令mksdcard在根文件夹中创建一个 sdcard 图像。

经过多次令人费解和遇到许多相同问题后,我找到了一种方法,可以让一切在新环境中正常工作。

环境

首先,确保您使用Android 推荐的~/.bashrc更改设置您的环境,包括:

export USE_CCACHE=1
ccache -M 10G

如果您尚未下载 Android 源代码,请按照以下步骤操作。

然后为环境设置一些功能:

$ . build/envsetup.sh

您现在应该实际执行其中一个函数来正确设置路径(正如李平中指出的那样,Android 构建说明中没有提到这一点!):

$ set_stuff_for_environment

第一次构建

开始建造! 例如:

$ lunch full-eng
$ make -j4

(这里,4 个线程非常适合我的机器。根据您的需要进行更改。)

构建完成后,只需启动模拟器:

$ emulator

后续构建

我发现要重建system.img ,您需要删除以下文件/目录:

out/target/product/generic/obj/PACKAGING/
out/target/product/generic/system.img

然后简单地重复:

$ make -j4
$ emulator

如何运行模拟器分步指南。 在下载的 android AOSP 源代码中运行模拟器如下:-

  • 步骤 1如果您在当前运行的终端 (Ubuntu) 中正确完成了构建和生成系统映像,那么它是直接的。 只需在终端中输入以下命令:-模拟器

  • 第 2 步如果您之前已经生成了系统映像并且您已经启动了一个全新的终端(Ubuntu),那么请一一运行以下命令:-

    1. source build/envsetup.sh
    2. lunch 1这里 1 是我的午餐类型,你可以用你的(7、8 等)替换它,最后
    3. emulator

就是这样,它将正确地为您的模拟器提供午餐。 谢谢你们快乐编码!!!!

仅供参考,我遇到了类似的问题,在尝试了不同的事情后,我发现解决方案是运行lunch (在运行 envsetup.sh 之后)并在这种情况下选择目标aosp_arm-eng 每次启动新 shell 时都必须这样做,因为它设置了模拟器运行 avd 所需的某些环境变量。前提是您已经构建了目标。

#!/usr/bin/env bash

ANDROID_BUILD_OUT=/path/to/android/build/output/
ANDROID_SDK_LINUX=/path/to/android/sdk
ANDROID_BUILD=${ANDROID_BUILD_OUT}/android/target/product/generic

${ANDROID_SDK_LINUX}/tools/emulator \
    -sysdir ${ANDROID_BUILD} \
    -system ${ANDROID_BUILD}/system.img \
    -ramdisk ${ANDROID_BUILD}/ramdisk.img \
    -data ${ANDROID_BUILD}/userdata.img \
    -kernel ${ANDROID_SDK_LINUX}/system-images/android-18/armeabi-v7a/kernel-qemu \
    -skindir ${ANDROID_SDK_LINUX}/platforms/android-18/skins \
    -skin WVGA800 \
    -scale 0.7 \
    -memory 512 \
    -partition-size 1024

在 Mac 上,您可以将以下行添加到您的 ~/.bash_profile 文件中。 相应地更改磁盘映像和 src 文件夹。

# start emulator
function startEmulator { hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android;
                         cd /Volumes/android/AndroidSrc;
                         source build/envsetup.sh;
                         lunch aosp_arm-eng;
                         /Volumes/android/AndroidSrc/out/host/darwin-x86/bin/emulator;  }

之后,创建一个新终端并输入:

startEmulator

您的模拟器可以启动。 这适用于mac。

只需在你的 shell 上输入 emulator ,它就会启动最新版本的模拟器,因为它的路径被设置为你的 shell 的 PATH 变量。

export MY_PWD=/work/ABC/Google_Android
export ANDROID_BUILD_TOP=/work/ABC/Google_Android
export PATH=$PATH:$MY_PWD/prebuilts/gcc/linux
export ANDROID_PRODUCT_OUT=$MY_PWD/out/target/product/generic

以上是我的环境设置。 ANDROID_BUILD_TOP 解决了

"emulator: ERROR: You did not specify a virtual device name, and the system
directory could not be found"

在我的机器上

我是这样表演的

我修改了./build/envsetup.sh文件,我只改了set_stuff_for_environment

function set_stuff_for_environment()
{
    setpaths
    set_sequence_number

    export ANDROID_BUILD_TOP=$(gettop)
    # With this environment variable new GCC can apply colors to warnings/errors
    export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
    export ASAN_OPTIONS=detect_leaks=0

    export ANDROID_PRODUCT_OUT=/var/www/android/out/target/product/generic_x86_64
    echo $ANDROID_PRODUCT_OUT
}

在项目的根目录下,我创建了一个名为 start.sh 的文件

#!/usr/bin/env bash

ANDROID_BUILD_OUT=/var/www/android/out
ANDROID_SDK_LINUX=/opt/android-studio/sdk
ANDROID_BUILD=${ANDROID_BUILD_OUT}/target/product/generic_x86_64

sudo chmod -R 777 /dev/kvm

source build/envsetup.sh

set_stuff_for_environment

./prebuilts/android-emulator/linux-x86_64/emulator \
    -debug-init -logcat '*:v' -verbose \
    -sysdir ${ANDROID_BUILD} \
    -system ${ANDROID_BUILD}/system.img \
    -ramdisk ${ANDROID_BUILD}/ramdisk.img \
    -skindir ${ANDROID_SDK_LINUX}/platforms/android-28/skins \
    -skin WVGA800 \
    -partition-size 2000
    -scale 0.7 \
    -memory 2000 \
    -data ${ANDROID_BUILD}/userdata.img \

如果你的机器上有“android sdk”,那么你的“模拟器”可以从那里而不是 /out/.... dir 中提取。 当您想使用“自己的”模拟器时,可以重命名“android sdk”目录。 然后你的“模拟器”将被拿起。

希望这对你有帮助!

问候 Sammoh

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM