Initial commit

This commit is contained in:
Lingfeng Yang 2020-12-04 10:38:15 -08:00
commit f6280c7358
6 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>runemu</string>
</dict>
</plist>

Binary file not shown.

View File

@ -0,0 +1,7 @@
#!/bin/bash
cd "${0%/*}"
export ANDROID_PRODUCT_OUT=`pwd`/aosp-master-arm64-v8a
export ANDROID_BUILD_TOP=$ANDROID_PRODUCT_OUT
./emulator/emulator

99
README.markdown Normal file
View File

@ -0,0 +1,99 @@
# Android Emulator M1 Preview
This is a preview of some basic Android emulation functionality on the M1. There are still many issues, but apps work at a basic level. To be updated soon with more fixes.
## Known issues
- Webview doesn't work
- No sound
- No device skins
- Video codecs not working
- 32 bit ARM apps won't work
- Graphical glitches in some Vulkan apps
- Popup on startup about not being able to find the ADB path (ADB will still notice the emulator if you have it installed though)
- When building, it may be faster to start then cancel the Python triggered build and then reissue `ninja -C objs install/strip` versus letting the Python triggered build finish.
## How to use
Go to the Github releases page, download a .dmg, drag to the Applications folder, and run. First few times it starts up it will take a while to show up, but subsequent launches will be faster.
If you've installed Android Studio and Android SDK and `adb` is available, the emulator should be visible from Studio and work (deploy built apps, debug apps, etc).
### How to configure
Edit `/Applications/Android\ Emulator.app/Contents/MacOS/aosp-master-arm64-v8a/config.ini`. Some notable options:
- `disk.dataPartition.size`: size of userdata. When reconfiguring, you'll also need to delete all `userdata*.img` files in that directory.
- `fastboot.forceColdBoot`,`fastboot.forceFastBoot`: whether to enable snapshots. Current default is snapshots disabled. Set `fastboot.forceColdBoot=no`,`fastboot.forceFastBoot=yes` to enable snapshots.
- `hw.lcd.density`: Virtual display DPI.
- `hw.lcd.width`,`hw.lcd.height`: Virtual display dimensions.
- `hw.ramSize`: RAM limit for the guest. (2GB minimum)
### How to wipe data
Remove all `userdata*.img` files in `/Applications/Android\ Emulator.app/Contents/MacOS/aosp-master-arm64-v8a/`.
## How to build your own emulator
### Building the engine
The emulator source code lives ([here](https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev)), but there are a bunch of other dependencies to download, so we use `repo`.
To build, first make sure you have Xcode and Xcode command line tools installed, and that you have Chromium `depot_tools` in your `PATH` ([link](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up)). Then:
mkdir emu
cd emu
repo init -u https://android.googlesource.com/platform/external/qemu --depth=1
repo sync -qcj 4
cd external/qemu
python android/build/python/cmake.py --target=darwin_aarch64
Note that canceling the python based build after it gets going and issuing just `ninja -C objs install/strip` may be faster.
The built artifacts are in `/path/to/external/qemu/objs/distribution/emulator`. They should be automatically signed. However, the binaries in `objs/` are not; to sign them, issue `./sign-objs-binaries.sh`. Note that this can only be done after `ninja -C objs install/strip` is successful.
### Building the system image
The system image is built from AOSP master `sdk_phone_arm64` with a few modifications. Ideally, let's be on a Linux host when building the system image---the build is relatively untested on M1 systems, and at least, we need to create a separate case sensitive partition for the AOSP repo. Assuming you're on Linux:
mkdir aosp-master
cd aosp-master
repo init -u https://android.googlesource.com/platform/manifest -b master --depth=1
repo sync -qcj 4
We first need to make an edit to remove all 32 bit support. Patch this change: [link](https://android-review.googlesource.com/c/platform/build/+/1518218) to `build/make/target/board/emulator_arm64/BoardConfig.mk`. Then:
source build/envsetup.sh
lunch sdk_phone_arm64-userdebug
make -j12
After that's done, we can use this script to package up the system image for use in `/Applications/Android\ Emulator.app/Contents/MacOS/aosp-master-arm64-v8a/`. Assuming you're still in the Android build environment:
echo $ANDROID_PRODUCT_OUT
export ZIPPED_NAME=$1
mkdir -p $ZIPPED_NAME/files
cd $ZIPPED_NAME/files
cp $ANDROID_PRODUCT_OUT/system-qemu.img system.img
cp $ANDROID_PRODUCT_OUT/vendor.img vendor.img
cp $ANDROID_PRODUCT_OUT/ramdisk.img ramdisk.img
cp $ANDROID_PRODUCT_OUT/ramdisk.img ramdisk.img
if [ -f $ANDROID_PRODUCT_OUT/kernel-ranchu-64 ]; then
cp $ANDROID_PRODUCT_OUT/kernel-ranchu-64 kernel-ranchu-64
else
cp $ANDROID_PRODUCT_OUT/kernel-ranchu kernel-ranchu
fi;
cp -r $ANDROID_PRODUCT_OUT/data .
cp -r $ANDROID_PRODUCT_OUT/advancedFeatures.ini advancedFeatures.ini
cp -r $ANDROID_PRODUCT_OUT/userdata.img .
cp -r $ANDROID_PRODUCT_OUT/encryptionkey.img .
cp -r $ANDROID_PRODUCT_OUT/build.prop .
mkdir system
cp -r $ANDROID_PRODUCT_OUT/build.prop system/build.prop
cp -r $ANDROID_PRODUCT_OUT/VerifiedBootParams.textproto .
cp -r $ANDROID_PRODUCT_OUT/source.properties .
cd ..
zip -1rq $ZIPPED_NAME.zip files
ls -l $ZIPPED_NAME.zip
Then, `$ZIPPED_NAME.zip` can be sent over to the M1 and the contents of its `files/` can be coped over into `/Applications/Android\ Emulator.app/Contents/MacOS/aosp-master-arm64-v8a/`.